Categories
Uncategorized

Easy Password Generator in PHP

This function will return a password of the length passed as a parameter. It's handy for automated processes to reset a password and mail a temporary password to a user who has forgotten their password, or for any other purpose which requires a random string.

The $p variable provides a list of characters eligible to be used in the password. You can see that I've omitted characters that can be mistaken, like a lower case "L" or an upper case "i" or a zero and upper case letter "O".

1
2
3
4
5
function GeneratePassword($len) {
	$p="2346789abcdefghjkmnprtuvwxyz";
	for( $i=0; $i < $len; $i++) { $s.= $p{rand(0,strlen($p))}; }
	return $s;
}

Leave a Reply