Php random password generation code. use the php custom function to generate a random password of the specified length. the password is a random string of lowercase letters and numbers. The length can be customized. A random password function is used to generate a random string of lowercase letters and numbers. The length can be customized.
The code is as follows:
/*
* Php automatically generates a new password user-defined function (with instance demo)
Applicable environment: PHP5.2.x/mysql 5.0.x
Code author: xujiajay
Contact: 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 )."
";
?>