php随机生成易于记忆的密码

WBOY
发布: 2016-07-25 08:46:10
原创
827 人浏览过
  1. function random_readable_pwd($length=10){
  2. // the wordlist from which the password gets generated
  3. // (change them as you like)
  4. $words = 'dog,cat,sheep,sun,sky,red,ball,happy,ice,';
  5. $words .= 'green,blue,music,movies,radio,green,turbo,';
  6. $words .= 'mouse,computer,paper,water,fire,storm,chicken,';
  7. $words .= 'boot,freedom,white,nice,player,small,eyes,';
  8. $words .= 'path,kid,box,black,flower,ping,pong,smile,';
  9. $words .= 'coffee,colors,rainbow,plus,king,tv,ring';
  10. // Split by ",":
  11. $words = explode(',', $words);
  12. if (count($words) == 0){ die('Wordlist is empty!'); }
  13. // Add words while password is smaller than the given length
  14. $pwd = '';
  15. while (strlen($pwd) $r = mt_rand(0, count($words)-1);
  16. $pwd .= $words[$r];
  17. }
  18. // append a number at the end if length > 2 and
  19. // reduce the password size to $length
  20. $num = mt_rand(1, 99);
  21. if ($length > 2){
  22. $pwd = substr($pwd,0,$length-strlen($num)).$num;
  23. } else {
  24. $pwd = substr($pwd, 0, $length);
  25. }
  26. return $pwd;
  27. }
  28. //使用范例:
  29. random_readable_pwd(10)
  30. => returns something like: pingwater6, radiohap28, sunwhite84, happykid44, etc...
复制代码

php


来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板