Re: Regular Expression Help: genreate alphanumeric, 8 chars
| From: | Burhan Khalid | Date: | Thu, 27 Nov 2003 13:21:29 +0000 |
| Subject: | Re: Regular Expression Help: genreate alphanumeric, 8 chars | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-171204@lists.php.net to get a copy of this message | ||
Shaun wrote:
Hi, I need to generate a lowercase alphanumeric passwrord thats 8 characters long, has anyone got a function that can do this?No, but I can write a quick one for you. Can't guarantee the uniqueness of the password being generated. function passgen() { srand((float) microtime() * 10000000); //Source arrays $letters = range('a','z'); $digits = range(1,9); //Get random items from arrays $char = array_rand($letters, 4); $num = array_rand($digits, 4); //Combine the two random items into one array for ($i = 0; $i <4; ++$i) {
$ran_char[] = $letters[$char[$i]];
$ran_num[] = $digits[$num[$i]];
}
//build our password
$password = array_unique(array_merge($ran_char, $ran_num));
//randomize it
shuffle($password);
return join("",$password);
}
echo passgen();
?>
--
Burhan Khalid
phplist[at]meidomus[dot]com
http://www.meidomus.com
-----------------------
"Documentation is like sex: when it is good,
it is very, very good; and when it is bad,
it is better than nothing."