これは実際にはあなたにとってより良いと思います。こちらをご覧くださいhttp://dev.michaelnorris.co.uk/tests/random_password.php
私は覚えていない他のソースからオンラインでそれを一緒にマッシュアップしたので、私はこの例を信用することはできませんが、とにかくここにあります。
<?php
// just so we know it is broken
error_reporting(E_ALL);
//string passType can be alpha, numeric, or alphanumeric defaults to alphanumeric int $length is the length of the password, defaults to eight
class randomPassword{
function __construct($passType='alphanumeric', $length=8, $rangeLength=9){
$this->setLength($length);
$this->setRangeLength($rangeLength);
$this->passType = $this->setPassType($passType);
}
function setRangeLength($rangeLength){
$this->rangeLength=$rangeLength;
}
// set the length of the password
private function setLength($length){
$this->length=$length;
}
// set the type of password
private function setPassType($passType){
return $passType.'Chars';
}
// return an array of numbers
private function numericChars(){
return range(0, $this->rangeLength);
}
// return an array of chars
private function alphaChars(){
return range('a', 'z');
}
// return an array of alphanumeric chars
private function alphaNumericChars(){
return array_merge($this->numericChars(), $this->alphaChars());
}
// return a string of chars
private function makeString(){
// here we set the function to call based on the password type
$funcName = $this->passType;
return implode($this->$funcName());
}
// shuffle the chars and return $length of chars
public function makePassword(){
return substr(str_shuffle($this->makeString()), 1, $this->length);
}
} // end class
function randomPassword($length) {
// create an array of chars to use as password
$chars = implode(array_merge(range(0,9), range('a', 'z')));
// randomly snarf $length number of array keys
return substr(str_shuffle($chars), 1, $length);
}
/*
try
{
$obj = new randomPassword('alphanumeric', 16, 100);
echo $obj->makePassword().'<br />';
}
catch(Exception $ex)
{
echo $ex->getMessage();
}
*/
echo strtoupper(randomPassword(5)).'-'.strtoupper(randomPassword(5)).'-'.strtoupper(randomPassword(5)).'-'.strtoupper(randomPassword(5)).'-'.strtoupper(randomPassword(5)).'-'.strtoupper(randomPassword(5));
?>