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".

function GeneratePassword($len) {
	for( $i=0; $i < $len; $i++) { $s.= $p{rand(0,strlen($p))}; }
	return $s;

About Editor