Php user-defined function for generating random passwords (reprinted and shared), php user-defined
Php user-defined function for generating random passwords
-
Release date: Edit: script School
Php user-defined function for generating random passwords
Generate a random password function. The generated password is a random string of lowercase letters and numbers. The length can be customized.
Copy the Code as follows: <? Php
/*
* 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 (). "<br> ";
Echo "New Password:". genPassword (5, 10). "<br> ";
?>
This article