[phpstudy]php 生成随机密码函数

更新时间:2016-07-13    来源:word    手机版     字体:

【www.bbyears.com--word】

名称:random_password()

#作者:克里斯亨特,杰里米阿什克拉夫特

#日期:1999年5月,2000年10月

#用途:返回一个作为密码使用随机单词。元音和辅音
#是交替给一个(希望)pronouncable,因此
#难忘的结果。

#用法:$ my_new_password = random_password();

#(c)1999年克里斯亨特。授予权限是自由包括此脚本
#您的程序。提供这个头是原封不动。

#2000年10月 - 茉莉酸 - Perl代码移植到PHP

function random_password() {

   $maxlen =  6;   # Default to 6

   # Build tables of vowels & consonants. Single vowels are repeated so that
   # resultant words are not dominated by dipthongs

   $vowel = array ("a","e", "i", "o", "u", "y", "ai", "au", "ay", "ea", "ee", "eu", "ia", "ie", "io", "oa", "oi", "oo", "oy");
   $consonant = array ("b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "qu", "r", "s", "t", "v", "w", "x", "z", "th", "st", "sh", "ph", "ng", "nd");
   $password = "";

   srand((double) microtime()*1000000);
   $vowelnext = (int)rand(0,1);  # Initialise to 0 or 1 (ie true or false)

   do {
      if ($vowelnext) {
         $password = $password.$vowel[rand(0,sizeof($vowel))];
      } else {
         $password = $password.$consonant[rand(0,sizeof($consonant))];
      }

      $vowelnext = !$vowelnext;    # Swap letter type for the next one

   } while (strlen($password) <$maxlen);

   return $password;

}

本文来源:http://www.bbyears.com/bangongshuma/25304.html

热门标签

更多>>

本类排行