Home >Backend Development >PHP Tutorial >改密码,该如何解决

改密码,该如何解决

WBOY
WBOYOriginal
2016-06-13 10:05:38889browse

改密码
我数据库里面有3000个用户,我初始将每个用户的用户名和密码都设为一样的了,现在我要改每个用户的密码(密码是自动生成含数字、字母、符号、密码为8位数),如果一个一个的改太麻烦了,请问那位能不能帮忙写个好点的程序一下将所有的密码改玩

------解决方案--------------------
include("dbConn.class.php");//连接数据库
$dbConn=new dbConn;
$str = 'ABCDEFGHIJKMNPQRSTUVWXYZ1234567890abcdefghijkmnpqrstuvwxyz'; //密码组成的字段
$l = strlen($str);
$sql="select * from users";//查询出结果集
$result=$dbConn->conn($sql);
$array=mysql_fetch_array($result);
while($array=mysql_fetch_array($result["rs"])){//用while循环结果集
$str_pwd="";
for($i=1;$i $num=rand(0,$l-1); 
$str_pwd.= $str[$num];
}
$sql="update users set password='$str_pwd' where username='".$array["username"]."'";//修改密码的SQL
$dbConn->conn($sql);//执行SQL语句
}
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn