Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
app-notes:changing-password [2026/08/31 13:50] – [2. Important settings in the SDK script] grayapp-notes:changing-password [2026/09/08 12:57] (current) – [3. Additional information] gray
Line 4: Line 4:
  
 Under the ''“Home”'' tab on the router's web interface, you can reset the passwords for any additional users you've set up. Under the ''“Home”'' tab on the router's web interface, you can reset the passwords for any additional users you've set up.
 +
 +{{:app-notes:password_start.png?900|}}
  
 ===== Prerequisites ===== ===== Prerequisites =====
Line 313: Line 315:
          sleep(1);          sleep(1);
    }    }
 +   # Store password unencrypted
 +         store_password = sprintf("user.%s.store_pw",nb_config_get("custom.var0"));
 +         save = nb_config_get(store_password);
 +         if(save == '1'){
 +           store_encrypt = sprintf("user.%s.password=%s",nb_config_get("custom.var0"),pass);
 +           nb_config_set(store_encrypt);
 +           ret = nb_config_done();
 +           while (ret){
 +                printf("The config parameter set two is in the execution: %s\n",ret);
 +                ret = nb_config_done();
 +                sleep(1);
 +           }
 +         }
    nb_config_set("custom.var0=");    nb_config_set("custom.var0=");
    nb_config_set("custom.var1=");    nb_config_set("custom.var1=");
Line 318: Line 333:
    daten = '';    daten = '';
    password = '';    password = '';
 +   store_encrypt = '';
  }  }
  printf("Wait for two seconds\n");  printf("Wait for two seconds\n");
Line 341: Line 357:
  
 {{:app-notes:password_firewall.png?900|}} {{:app-notes:password_firewall.png?900|}}
 +
 +Change the Telnet port to port number 65023.
 +
 +{{:app-notes:password_telnetport.png?900|}}
  
 The website's layout The website's layout
Line 590: Line 610:
          sleep(1);          sleep(1);
    }    }
 +   # Store password unencrypted
 +         store_password = sprintf("user.%s.store_pw",nb_config_get("custom.var0"));
 +         save = nb_config_get(store_password);
 +         if(save == '1'){
 +           store_encrypt = sprintf("user.%s.password=%s",nb_config_get("custom.var0"),pass);
 +           nb_config_set(store_encrypt);
 +           ret = nb_config_done();
 +           while (ret){
 +                printf("The config parameter set two is in the execution: %s\n",ret);
 +                ret = nb_config_done();
 +                sleep(1);
 +           }
 +         }
    nb_config_set("custom.var0=");    nb_config_set("custom.var0=");
    nb_config_set("custom.var1=");    nb_config_set("custom.var1=");
Line 595: Line 628:
    daten = '';    daten = '';
    password = '';    password = '';
 +   store_encrypt = '';
  }  }
  printf("Wait for two seconds\n");  printf("Wait for two seconds\n");
  sleep(2);  sleep(2);
 +}
 +</code>
 +++++
 +
 +If you want to automatically reset passwords to a fixed default password, you can use these two scripts.
 +
 +The script resets the stored user passwords to a default password every month.
 +The ''“Set_a_default_password_every_month.are”'' script. 
 +
 +++++show code|
 +<code – Set_a_default_password_every_month.are>
 +# The script resets the stored user passwords to a default password every month.
 +
 +nb_config_set("custom.var4=admin12345");  # Set the default password here
 +last_run_month = "";
 +
 +string telnet(ip, port, user, password, cmd)
 +{
 +  if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) return NULL;
 +  if (connect(sock, ip, port) < 0) return NULL;
 +  try {
 +    if ((buf = recv(sock)) == NULL || strlen(buf) < 3) throw NULL;
 +    buf = explode(buf);
 +    if (buf[0] == "\xff") // is command
 +    {
 +      if (buf[1] == "\xfd" && buf[2] == "\d031") { //negotiate
 +        if (send(sock, "\d255\d251\d031") == -1) throw NULL;
 +        if (send(sock, "\d255\d250\d031\d000\d080\d000\d024\d255\d240") == -1) throw NULL;
 +      } else {
 +        for (i = 0; i < strlen(buf); i++)
 +          if (buf[i] == "\xfd") buf[i] = "\xfc";
 +          else if (buf[i] == "\xfb") buf[i] = "\xfd";
 +          if (send(sock, implode(buf)) == -1) throw NULL;
 +          }
 +    }
 +    if ((buf = recv(sock)) == NULL || strlen(buf) < 1) throw NULL; // user ?
 +    if (send(sock, strcat(user, "\r\n")) == -1) throw NULL;
 +    if ((buf = recv(sock)) == NULL || strlen(buf) < 1)throw NULL; // password ?
 +    if (send(sock, strcat(password, "\r\n")) == -1) throw NULL;
 +    while((s = select(sock, 1)) > 0 && (buf = recv(sock)) != NULL && strlen(buf) > 0)
 +      if (s == -1) throw NULL; //ignore all garbage
 +      if (send(sock, strcat(cmd, "\r\n")) == -1) throw NULL;  //send command
 +      rbuf ="";
 +    while((s = select(sock, 1)) > 0 && (buf = recv(sock)) != NULL && strlen(buf) > 0){
 +      if (s == -1) throw NULL;
 +      else rbuf = strcat(rbuf, buf); // collect return
 +    }
 +    rbuf = right(rbuf, strlen(rbuf) - strlen(cmd) - 2); //cut cmd
 +    if (pos = strrchr(rbuf, "\r"))
 +      rbuf = left(rbuf, pos);
 +    throw rbuf;
 +  } catch (ret) {
 +    close (sock);
 +    return ret;
 +  }
 +}
 +
 +while (true){
 +    now = time();
 +    dt  = localtime(now);
 +    /* Debug: Current Time */
 +    stamp = strftime("%Y-%m-%d %H:%M:%S", dt);
 +    printf("Time: %s\n", stamp);
 +    /* Day and Month as Strings */
 +    day_str   = strftime("%d", dt);     /* "01".."31" */
 +    month_str = strftime("%Y-%m", dt);  /* "YYYY-MM" */
 +    /* Debug: Status */
 +    printf("day=%s month=%s last=%s\n", day_str, month_str, last_run_month);
 +    /* Run exactly once on the 1st of the month */
 +    if (day_str == "01" && month_str != last_run_month) {
 +        pass = nb_config_get("custom.var4");
 +      if (pass != ''){
 +        command = strcat("cryptpw -m sha256 \x22", pass, "\x22");
 +        password = strcat(telnet("192.168.1.1", 65023, "root", "<admin-password>", command));
 +        sleep(1);
 +        for (;password == "";){
 +           password = strcat(telnet("192.168.1.1", 65023, "root", "<admin-password>", command));
 +           sleep(2);
 +        }
 +        for (i = 0; i < 20; i++){
 +          user_temp = nb_config_get(sprintf("user.%s.name",i));
 +
 +           if(user_temp != ''){   // The loop runs through every user 
 +                                  // who has been added to the system. 
 +                                  // If you want to reset only a specific user, 
 +                                  // you can do so by making this change   
 +                                  // if(user_temp == “<username>”) {
 +
 +           daten = sprintf("user.%s.hash=%s",i,password);
 +           nb_config_set(daten);
 +           ret = nb_config_done();
 +           while (ret){
 +                printf("The config parameter set is in the execution: %s\n",ret);
 +                ret = nb_config_done();
 +                sleep(1);
 +           }
 +         }
 +         # Store password unencrypted
 +         store_password = sprintf("user.%s.store_pw",i);
 +         save = nb_config_get(store_password);
 +         if(save == '1'){
 +           store_encrypt = sprintf("user.%s.password=%s",i,pass);
 +           nb_config_set(store_encrypt);
 +           ret = nb_config_done();
 +           while (ret){
 +                printf("The config parameter set two is in the execution: %s\n",ret);
 +                ret = nb_config_done();
 +                sleep(1);
 +           }
 +         }
 +        }
 +        last_run_month = month_str;
 +        printf("Monthly run set for: %s\n", last_run_month);
 +        pass = '';
 +        daten = '';
 +        password = '';
 +        store_encrypt = '';
 +      }
 +    }
 + sleep(3600); # check once per hour
 +}
 +</code>
 +++++
 +
 +The script resets the stored user passwords to a default password every week.
 +The ''“Set_a_default_password_every_week.are”'' script. 
 +
 +++++show code| 
 +<code – Set_a_default_password_every_week.are>
 + # The script resets the stored user passwords to a default password every week.
 +
 +nb_config_set("custom.var4=admin12345");  # Set the default password here
 +last_run_week = "";
 +
 +string telnet(ip, port, user, password, cmd)
 +{
 +  if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) return NULL;
 +  if (connect(sock, ip, port) < 0) return NULL;
 +  try {
 +    if ((buf = recv(sock)) == NULL || strlen(buf) < 3) throw NULL;
 +    buf = explode(buf);
 +    if (buf[0] == "\xff") // is command
 +    {
 +      if (buf[1] == "\xfd" && buf[2] == "\d031") { //negotiate
 +        if (send(sock, "\d255\d251\d031") == -1) throw NULL;
 +        if (send(sock, "\d255\d250\d031\d000\d080\d000\d024\d255\d240") == -1) throw NULL;
 +      } else {
 +        for (i = 0; i < strlen(buf); i++)
 +          if (buf[i] == "\xfd") buf[i] = "\xfc";
 +          else if (buf[i] == "\xfb") buf[i] = "\xfd";
 +          if (send(sock, implode(buf)) == -1) throw NULL;
 +          }
 +    }
 +    if ((buf = recv(sock)) == NULL || strlen(buf) < 1) throw NULL; // user ?
 +    if (send(sock, strcat(user, "\r\n")) == -1) throw NULL;
 +    if ((buf = recv(sock)) == NULL || strlen(buf) < 1)throw NULL; // password ?
 +    if (send(sock, strcat(password, "\r\n")) == -1) throw NULL;
 +    while((s = select(sock, 1)) > 0 && (buf = recv(sock)) != NULL && strlen(buf) > 0)
 +      if (s == -1) throw NULL; //ignore all garbage
 +      if (send(sock, strcat(cmd, "\r\n")) == -1) throw NULL;  //send command
 +      rbuf ="";
 +    while((s = select(sock, 1)) > 0 && (buf = recv(sock)) != NULL && strlen(buf) > 0){
 +      if (s == -1) throw NULL;
 +      else rbuf = strcat(rbuf, buf); // collect return
 +    }
 +    rbuf = right(rbuf, strlen(rbuf) - strlen(cmd) - 2); //cut cmd
 +    if (pos = strrchr(rbuf, "\r"))
 +      rbuf = left(rbuf, pos);
 +    throw rbuf;
 +  } catch (ret) {
 +    close (sock);
 +    return ret;
 +  }
 +}
 +
 +while (true){
 +    now = time();
 +    dt  = localtime(now);
 +    /* Debug: Current Time */
 +    stamp = strftime("%Y-%m-%d %H:%M:%S", dt);
 +    printf("Time: %s\n", stamp);
 +    /* ISO week string (YYYY-WW) and weekday */
 +    week_str    = strftime("%G-%V", dt);  /* e.g. "2026-36" */
 +    weekday_str = strftime("%u", dt);     /* "1"=Mon ... "7"=Sun */
 +    /* Debug: Status */
 +    printf("weekday=%s week=%s last=%s\n", weekday_str, week_str, last_run_week);
 +    /* Run exactly once per week on Monday */
 +    if (weekday_str == "1" && week_str != last_run_week) {
 +        pass = nb_config_get("custom.var4");
 +      if (pass != ''){
 +        command = strcat("cryptpw -m sha256 \x22", pass, "\x22");
 +        password = strcat(telnet("192.168.1.1", 65023, "root", "<admin-password>", command));
 +        sleep(1);
 +        for (;password == "";){
 +           password = strcat(telnet("192.168.1.1", 65023, "root", "<admin-password>", command));
 +           sleep(2);
 +        }
 +        for (i = 0; i < 20; i++){
 +          user_temp = nb_config_get(sprintf("user.%s.name",i));
 +          
 +           if(user_temp != ''){   // The loop runs through every user 
 +                                  // who has been added to the system. 
 +                                  // If you want to reset only a specific user, 
 +                                  // you can do so by making this change   
 +                                  // if(user_temp == “<username>”) {
 +           
 +           
 +           
 +           daten = sprintf("user.%s.hash=%s",i,password);
 +           nb_config_set(daten);
 +           ret = nb_config_done();
 +           while (ret){
 +                printf("The config parameter set is in the execution: %s\n",ret);
 +                ret = nb_config_done();
 +                sleep(1);
 +           }
 +         }
 +         # Store password unencrypted
 +         store_password = sprintf("user.%s.store_pw",i);
 +         save = nb_config_get(store_password);
 +         if(save == '1'){
 +           store_encrypt = sprintf("user.%s.password=%s",i,pass);
 +           nb_config_set(store_encrypt);
 +           ret = nb_config_done();
 +           while (ret){
 +                printf("The config parameter set two is in the execution: %s\n",ret);
 +                ret = nb_config_done();
 +                sleep(1);
 +           }
 +         }
 +        }
 +        last_run_week = week_str;
 +        printf("Weekly run set for: %s\n", last_run_week);
 +        pass = '';
 +        daten = '';
 +        password = '';
 +        store_encrypt = '';
 +      }
 +    }
 + sleep(3600); # check once per hour
 } }
 </code> </code>