I changed the password to 3000 users in my database. I initially set the username and password of each user to the same, now I want to change the password of each user (the password is automatically generated with 8 digits including digits, letters, symbols, and passwords). If one change is too troublesome, could you help me write a better program and change all the passwords? Solution: -------------------- & lt ;? Phpinclude (& quot; dbConn. c change password
There are 3000 users in my database. I initially set the usernames and passwords of each user to the same, now I want to change the password of each user (the password is automatically generated with 8 digits including digits, letters, symbols, and passwords). If one change is too troublesome, could you help me write a better program and change all the passwords?
------ Solution --------------------
Include ("dbConn. class. php"); // connect to the database
$ DbConn = new dbConn;
$ Str = 'abcdefghijkmnpqrstuvwxyz1234567890abcdefghijkmnpqrstuvwxyz '; // password composition field
$ L = strlen ($ str );
$ SQL = "select * from users"; // query the result set.
$ Result = $ dbConn-> conn ($ SQL );
$ Array = mysql_fetch_array ($ result );
While ($ array = mysql_fetch_array ($ result ["rs"]) {// use the while loop result set
$ Str_pwd = "";
For ($ I = 1; $ I <= 8; $ I ++) {// obtain the password eight times in a loop
$ Num = rand (0 L-1 );
$ Str_pwd. = $ str [$ num];
}
$ SQL = "update users set password = '$ str_pwd' where username = '". $ array ["username"]. "'"; // SQL statement used to change the password
$ DbConn-> conn ($ SQL); // execute an SQL statement
}
?>