Secure Password Generator
if (isset($_POST['level'])) {
$level = $_POST['level'];
$length = $_POST['length'];
} else {
$level = 4;
$length = 10; }
echo "
function generatePassword($length,$level){
if ($length > 15) $length = 15;
list($usec, $sec) = explode(‘ ‘, microtime());
srand((float) $sec + ((float) $usec * 100000));
$str1 = “0123456789″; $str2 = “abcdfghjkmnpqrstvwxyz”;
$str3 = “ABCDEFGHIJKLMNOPQRSTUVWXYZ”; $str4 = “!@#$%&*_+=-”;
$validchars[1] = $str1;
$validchars[2] = $str1.$str2;
$validchars[3] = $str1.$str2.$str3;
$validchars[4] = $str1.$str2.$str3.$str4;
$password = “”;$counter = 0;
while ($counter < $length) {
$actChar = substr($validchars[$level],
rand(0, strlen($validchars[$level])-1), 1);
// All character must be different
if (!strstr($password, $actChar)) {
$password .= $actChar;
$counter++;
}
}
return $password;}
?>
A quick and easy way to generate a password. Just enter the number of characters and complexity. Obviously the longer and more complex, the more secure the password.
Easier than having to think it up myself