コード例 #1
0
 static function createPassword($passwordLength, $seed = false)
 {
     $chars = 0;
     $password = '';
     if ($passwordLength < 1) {
         $passwordLength = 1;
     }
     $decimal = 0;
     while ($chars < $passwordLength) {
         if ($seed == false) {
             $seed = time() . ":" . mt_rand();
         }
         $text = md5($seed);
         $characterTable = eZUser::passwordCharacterTable();
         $tableCount = count($characterTable);
         for ($i = 0; $chars < $passwordLength and $i < 32; ++$chars, $i += 2) {
             $decimal += hexdec(substr($text, $i, 2));
             $index = $decimal % $tableCount;
             $character = $characterTable[$index];
             $password .= $character;
         }
         $seed = false;
     }
     return $password;
 }