-
-
/*
- * php自动生成新密码自定义函数
- 适用环境: PHP5.2.x / mysql 5.0.x
- 代码作者: xujiajay
- * */
- function genPassword($min = 5, $max = 8)
- {
- $validchars="abcdefghijklmnopqrstuvwxyz123456789";
- $max_char=strlen($validchars)-1;
- $length=mt_rand($min,$max);
- $password = "";
- for($i=0;$i {
- $password.=$validchars[mt_rand(0,$max_char)];
- }
- return $password;
- }
- echo "新密码:".genPassword()."
";
- echo "新密码:".genPassword(5,10)."
";
- ?>
复制代码
方法2:
-
-
/**
- php 生成随机密码
- */
- function generatePassword($length=8)
- {
- $chars = array_merge(range(0,9),
- range('a','z'),
- range('A','Z'),
- array('!','@','$','%','^','&','*'));
- shuffle($chars);
- $password = '';
- for($i=0; $i $password .= $chars[$i];
- }
- return $password;
- }
echo "新密码:" . generatePassword(16);
- ?>
-
复制代码
|