-
- /*
- * php automatically generates a new password custom function
- Applicable environment: PHP5.2.x / mysql 5.0.x
- Code author: xujiajay
- * */
- 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)."
";
- ?>
Copy code
Method 2:
-
-
/** - php generate random password
- */
- function generatePassword($length=8)
- {
- $chars = array_merge(range(0,9),
- range ('a','z'),
- range('A','Z'),
- array('!','@','$','%','^','&',' *'));
- shuffle($chars);
- $password = '';
- for($i=0; $i<8; $i++) {
- $password .= $chars[$i];
- }
- return $password;
- }
echo "New password:" . generatePassword(16);
- ?>
-
Copy code
|