|
Description:
Improved version of make_password submitted by Shane Caraveo. This one adds options to use upper case characters, numerics and special characters.
Source: Text Source
function make_password($length,$strength=0) {
$vowels = 'aeiouy';
$consonants = 'bdghjlmnpqrstvwxz';
if ($strength & 1) {
$consonants .= 'BDGHJLMNPQRSTVWXZ';
}
if ($strength & 2) {
$vowels .= "AEIOUY";
}
if ($strength & 4) {
$consonants .= '0123456789';
}
if ($strength & 8) {
$consonants .= '@#$%^';
}
$password = '';
$alt = time() % 2;
srand(time());
for ($i = 0; $i < $length; $i++) {
if ($alt == 1) {
$password .= $consonants[(rand() % strlen($consonants))];
$alt = 0;
} else {
$password .= $vowels[(rand() % strlen($vowels))];
$alt = 1;
}
}
return $password;
}
Discussion:
After seeing the comments regarding password security I amended Shane's original code to include a strength option. This is a bit mask of the various options: 1 adds in upper case consonants, 2 adds in upper case vowels, 4 adds in numbers and 8 adds in special characters.
make_password(8,3); would geberate an 8 character password with upper and lower consonants and vowels.
make_password(8,5); would generate an 8 character password with upper case consonants and numbers.
It can still generate a valid dictionary entry at random (unless numbers and special characters are included)
|