A function that generates a random password. The password is a random string of lowercase letters and numbers. The length can be customized.
Copy the codeThe code is as follows:
/*
* php automatically generates new password custom function (with example demonstration)
Applicable environment: PHP5.2.x / mysql 5.0.x
Code author: xujiajay
Contact information: xujiaphp@gmail. com
* */
function genPassword($min = 5, $max = 8)
{
$validchars="abcdefghijklmnopqrstuvwxyz123456789";
$max_char=strlen($validchars)-1;
$length=mt_ rand($min, $max);
$password = "";
for($i=0;$i<$length;$i++ )
{
$password.=$validchars[mt_rand(0,$max_char)];
}
return $password;
}
echo "New password:".genPassword()."
";
echo "New password:".genPassword(5,10)."
";
?> ;