- <?php
- /*
- * php自动生成新密码自定义函数(带实例演示)
- 适用环境: PHP5.2.x / mysql 5.0.x
- 代码作者: xujiajay
- 联系方式: 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 "新密码:".genPassword()."<br>";
- echo "新密码:".genPassword(5,10)."<br>";
- ?>
- //该片段来自于http://www.codesnippet.cn/detail/24112012640.html
来源: http://www.codesnippet.cn/detail/24112012640.html