function generatePassword($length=9, $strength=0) { $vowels = 'aeuy'; $consonants = 'bdghjmnpqrstvz'; if ($strength & 1) { $consonants .= 'BDGHJLMNPQRSTVWXZ'; } if ($strength & 2) { $vowels .= "AEUY"; } if ($strength & 4) { $consonants .= '23456789'; } if ($strength & 8) { $consonants .= '@#$%'; } $password = ''; $alt = time() % 2; 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; } echo generatePassword(8,4) . '<br>'; echo generatePassword(8,4) . '<br>'; echo generatePassword(8,4) . '<br>'; echo generatePassword(8,4) . '<br>'; echo generatePassword(8,4) . '<br>';
Version 1 Example:
‘;
echo generatePassword(8,4) . ‘
‘;
echo generatePassword(8,4) . ‘
‘;
echo generatePassword(8,4) . ‘
‘;
echo generatePassword(8,4) . ‘
‘;
?>
if (!$length){ $length = '8'; } if (!$withchar){ $withchar = 'no'; } if (!$lowers){ $lowers = 'yes'; } if (!$uppers){ $uppers = 'yes'; } if (!$nums){ $nums = 'yes'; } if ($withchar == 'no' AND $lowers == 'no' AND $uppers == 'no' AND $nums == 'no'){ print("<b><font color=red>Error:</font> You MUST Select SOMETHING!<BR><HR>We Suggest Selecting What You Want First & Before Selecting What You Don't Want..<HR></b>"); exit; } if ($lowers == 'yes'){$char[] = 'a'; $char[] = 'b'; $char[] = 'c'; $char[] = 'd';$char[] = 'e';$char[] = 'f';$char[] = 'g';$char[] = 'h';$char[] = 'i';$char[] = 'j';$char[] = 'k';$char[] = 'l';$char[] = 'm';$char[] = 'n';$char[] = 'o';$char[] = 'p';$char[] = 'q';$char[] = 'r';$char[] = 's';$char[] = 't';$char[] = 'u';$char[] = 'v';$char[] = 'w';$char[] = 'x';$char[] = 'y';$char[] = 'z';} if ($uppers == 'yes'){$char[] = 'A';$char[] = 'B';$char[] = 'C';$char[] = 'D';$char[] = 'E';$char[] = 'F';$char[] = 'G';$char[] = 'H';$char[] = 'I';$char[] = 'J';$char[] = 'K';$char[] = 'L';$char[] = 'M';$char[] = 'N';$char[] = 'O';$char[] = 'P';$char[] = 'Q';$char[] = 'R';$char[] = 'S';$char[] = 'T';$char[] = 'U';$char[] = 'V';$char[] = 'W';$char[] = 'X';$char[] = 'Y';$char[] = 'Z';} if ($nums == 'yes'){$char[] = '0';$char[] = '1';$char[] = '2';$char[] = '3';$char[] = '4';$char[] = '5';$char[] = '6';$char[] = '7';$char[] = '8';$char[] = '9';} if ($withchar == 'yes'){$char[] = '!';$char[] = '@';$char[] = '$';$char[] = '^';$char[] = '+';$char[] = '|';$char[] = '>';$char[] = '<';} $num = count($char);$num -= 1; for ($i = 0; $i < 9; $i++){ srand((double)microtime()*1000000); $randnum = rand(0,$num); $password .= "$char[$randnum]"; $randnum = rand(0,$num); $password .= "$char[$randnum]";}
Version 2 Example:
Error: You MUST Select SOMETHING!
We Suggest Selecting What You Want First & Before Selecting What You Don’t Want..
“); exit; }
if ($lowers == ‘yes’){$char[] = ‘a’; $char[] = ‘b’; $char[] = ‘c’; $char[] = ‘d’;$char[] = ‘e’;$char[] = ‘f’;$char[] = ‘g’;$char[] = ‘h’;$char[] = ‘i’;$char[] = ‘j’;$char[] = ‘k’;$char[] = ‘l’;$char[] = ‘m’;$char[] = ‘n’;$char[] = ‘o’;$char[] = ‘p’;$char[] = ‘q’;$char[] = ‘r’;$char[] = ‘s’;$char[] = ‘t’;$char[] = ‘u’;$char[] = ‘v’;$char[] = ‘w’;$char[] = ‘x’;$char[] = ‘y’;$char[] = ‘z’;}
if ($uppers == ‘yes’){$char[] = ‘A’;$char[] = ‘B’;$char[] = ‘C’;$char[] = ‘D’;$char[] = ‘E’;$char[] = ‘F’;$char[] = ‘G’;$char[] = ‘H’;$char[] = ‘I’;$char[] = ‘J’;$char[] = ‘K’;$char[] = ‘L’;$char[] = ‘M’;$char[] = ‘N’;$char[] = ‘O’;$char[] = ‘P’;$char[] = ‘Q’;$char[] = ‘R’;$char[] = ‘S’;$char[] = ‘T’;$char[] = ‘U’;$char[] = ‘V’;$char[] = ‘W’;$char[] = ‘X’;$char[] = ‘Y’;$char[] = ‘Z’;}
if ($nums == ‘yes’){$char[] = ‘0’;$char[] = ‘1’;$char[] = ‘2’;$char[] = ‘3’;$char[] = ‘4’;$char[] = ‘5’;$char[] = ‘6’;$char[] = ‘7’;$char[] = ‘8’;$char[] = ‘9’;}
if ($withchar == ‘yes’){$char[] = ‘!’;$char[] = ‘@’;$char[] = ‘$’;$char[] = ‘^’;$char[] = ‘+’;$char[] = ‘|’;$char[] = ‘>’;$char[] = ‘<';}
$num = count($char);$num -= 1;
for ($i = 0; $i < 9; $i++){
srand((double)microtime()*1000000);
$randnum = rand(0,$num);
$password .= "$char[$randnum]";
$randnum = rand(0,$num);
$password .= "$char[$randnum]";}
echo $password;
?>
Last Updated on October 26, 2015