Skip to content

Instantly share code, notes, and snippets.

@yeroon
Created August 23, 2011 14:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yeroon/1165266 to your computer and use it in GitHub Desktop.
Save yeroon/1165266 to your computer and use it in GitHub Desktop.
Generate a random password of arbitrary length consisting of lowercased letters, uppercased letters and numbers, except for 'o', 'i', 'l', 'O', 'i' and 1.
/**
* Generate a password of arbitrary length, consisting of lowercased letters,
* uppercased letters and numbers, except for 'o', 'i', 'l', 'O', 'I', and 1.
*
* @param int $length Defaults to 8
* @return string password
*/
function simple_password($length = 8)
{
$exclude = array('o', 'i', 'l', 'O', 'I', 1);
$lowercase = range('a', 'z');
$uppercase = range('A', 'Z');
$numbers = range(0, 9);
$characters = array_merge($lowercase, $uppercase, $numbers);
$characters = array_diff($characters, $exclude);
shuffle($characters);
$password = implode(array_rand(array_flip($characters), $length));
return $password;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment