Random Password Generator with PHP
This function will generate a random password based off of a character list that you specify. This is very useful for a user registration form.
Example: Instead of asking a user for their desired password on a sign up form, generate a random one for them and email it to them. This poses less of a security risk by emailing them a random password and less fields for them to to fill out when signing up.
PHP:
-
function randomPassword($length = 7) {
-
// empty password
-
$password = "";
-
// define possible characters
-
$possible = "23456789abcdefghjkmnpqrstuvwxyz";
-
// add random characters until $length is reached
-
$i = 0;
-
while ($i <$length) {
-
// pick a random character from the possible ones
-
// don't allow duplicate characters
-
$password .= $char;
-
$i++;
-
}
-
}
-
return $password;
-
}

My name is Noah Everett. I live in Tulsa, OK. I started 