php隨機產生易於記憶的密碼

WBOY
發布: 2016-07-25 08:46:10
原創
820 人瀏覽過
  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) < $length){
  16. $r = mt_rand(0, count($words)-1);
  17. $pwd .= $words[$r];
  18. }
  19. // append a number at the end if length > 2 and
  20. // reduce the password size to $length
  21. $num = mt_rand(1, 99);
  22. if ($length > 2){
  23. $pwd = substr($pwd,0,$length-strlen($num)).$num;
  24. } else {
  25. $pwd = substr($pwd, 0, $length);
  26. }
  27. return $pwd;
  28. }
  29. //使用范例:
  30. random_readable_pwd(10)
  31. => returns something like: pingwater6, radiohap28, sunwhite84, happykid44, etc...
复制代码

php


來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板