Random Password Generator
Tags: password

Passwords are like underwear
They should be changed often, not left in the open, and not shared with anyone…
So, need a quick, random password?
Well, here’s a script I wrote that generates a random password with a given number of characters, with the choice to select Upper case, Lower case, numbers and / or special characters.
It excludes characters that are easily confused (lower case l & number 1, capital O, number 0, etc).
[random_password]
Here’s the source code
Web Form:
Password will appear here.
randomPass-process.php:
'number of characters' can not be less than selection of characters to use.
";
break;
}
//no errors, generate the password
$password = "";
for ($i = 0; $i < $length; $i++)
{
$password .= $toUse[(rand() % strlen($toUse))];
}
//define the array to return
$passwordArray[0] = $password;
$passwordArray[1] = $upperCase;
$passwordArray[2] = $lowerCase;
$passwordArray[3] = $numbers;
$passwordArray[4] = $specialChars;
//check that the password contains at LEAST 1 character from each selected category
$hasUpper = strpbrk($passwordArray[0],$passwordArray[1]);
$hasLower = strpbrk($passwordArray[0],$passwordArray[2]);
$hasNumber = strpbrk($passwordArray[0],$passwordArray[3]);
$hasSpecChar = strpbrk($passwordArray[0],$passwordArray[4]);
if(($useUpperCase == "true" && $hasUpper == "") || ($useLowerCase == "true" && $hasLower == "") || ($useNumbers == "true" && $hasNumber == "") || ($useSpecialChars == "true" && $hasSpecChar == ""))
{
return "FALSE";
}
//it contains everything it needs... return the password
else
{
$password = "Your password is:
".$passwordArray[0]."";
return $password;
}
}
do // get the password to display
{
$password = fGenerateRandomPassword($_GET['length'],$_GET['useUpper'],$_GET['useLower'],$_GET['useNumbers'],$_GET['useSpecialChars']);
}
while($password=="FALSE") // until it's not returned as 'FALSE'
?>
document.getElementById('passwordBlock').innerHTML = '';
