[PHP] PHP 自动生成密码 →→→→→进入此内容的聊天室

来自 , 2020-03-11, 写在 PHP, 查看 148 次.
URL http://www.code666.cn/view/aac61539
  1. function generatePassword($length=9, $strength=0) {
  2.     $vowels = 'aeuy';
  3.     $consonants = 'bdghjmnpqrstvz';
  4.     if ($strength >= 1) {
  5.         $consonants .= 'BDGHJLMNPQRSTVWXZ';
  6.     }
  7.     if ($strength >= 2) {
  8.         $vowels .= "AEUY";
  9.     }
  10.     if ($strength >= 4) {
  11.         $consonants .= '23456789';
  12.     }
  13.     if ($strength >= 8 ) {
  14.         $vowels .= '@#$%';
  15.     }
  16.  
  17.     $password = '';
  18.     $alt = time() % 2;
  19.     for ($i = 0; $i < $length; $i++) {
  20.         if ($alt == 1) {
  21.             $password .= $consonants[(rand() % strlen($consonants))];
  22.             $alt = 0;
  23.         } else {
  24.             $password .= $vowels[(rand() % strlen($vowels))];
  25.             $alt = 1;
  26.         }
  27.     }
  28.     return $password;
  29. }
  30.  

回复 "PHP 自动生成密码"

这儿你可以回复上面这条便签

captcha