generate-password.php
http://www.akademia.ch/info/php/generate-password.php — vaebia —
<?
function generate_password($length){
// A List of vowels and vowel sounds that we can insert in
// the password string
$vowels = array("a", "e", "i", "o", "u", "ae", "ou", "io",
"ea", "ou", "ia", "ai");
// A List of Consonants and Consonant sounds that we can insert
// into the password string
$consonants = array("b", "c", "d", "g", "h", "j", "k", "l", "m",
"n", "p", "r", "s", "t", "u", "v", "w",
"tr", "cr", "fr", "dr", "wr", "pr", "th",
"ch", "ph", "st", "sl", "cl");
// For the call to rand(), saves a call to the count() function
// on each iteration of the for loop
$vowel_count = count($vowels);
$consonant_count = count($consonants);
// From $i .. $length, fill the string with alternating consonant
// vowel pairs.
for ($i = 0; $i < $length; ++$i) {
$pass .= $consonants[rand(0, $consonant_count - 1)] .
$vowels[rand(0, $vowel_count - 1)];
}
// Since some of our consonants and vowels are more than one
// character, our string can be longer than $length, use substr()
// to truncate the string
return substr($pass, 0, $length);
}
echo generate_password(6);
?>