Created
August 23, 2011 14:26
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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