RE: [PHP] Random string
| From: | Chad Day | Date: | Fri, 15 Sep 2000 14:17:21 +0000 |
| Subject: | RE: [PHP] Random string | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-16922@lists.php.net to get a copy of this message | ||
Here's a password generation function I found somewhere..
function genpassword($length){
srand((double)microtime()*1000000);
$vowels = array("a", "e", "i", "o", "u");
$cons = array("b", "c", "d", "g", "h",
"j", "k", "l", "m", "n", "p",
"r", "s", "t", "u", "v", "w",
"tr",
"cr", "br", "fr", "th", "dr", "ch",
"ph", "wr", "st", "sp", "sw", "pr",
"sl", "cl");
$num_vowels = count($vowels);
$num_cons = count($cons);
for($i = 0; $i < $length; $i++){
$password .= $cons[rand(0, $num_cons - 1)] . $vowels[rand(0,
$num_vowels - 1)];
}
return substr($password, 0, $length);
}
can make it as long or short as you want..
Chad
-----Original Message-----
From: n e t b r a i n [mailto:net-brain@net-brain.net]
Sent: Friday, September 15, 2000 4:17 AM
To: php-general@lists.php.net
Subject: [PHP] Random string
Hi,
I'm in trouble in order to implement a small function for a random
alphanumeric string of 8 charcters lenght (well, I mean: a password of 8
chars ...)
Reading the Wrox php book, I've founded this:
function random($lenght) {
$possibili="0123456789+-zxcvbnmlkjhgfdsapoiuytrewqZXCVBNMLKJHGFDSAPOIUYTREWQ
";
$stringa=" ";
while(strlen($stringa) < $lenght) {
$stringa .=substr($possibili, mt_rand(0, strlen($possibili)
-1), 1);
}
echo($stringa);
}
random(8);
But the main problem is that it seem doesn't work ... infact it produce
often a php_time_out ...
Anyone could help me with suggestion or show me a small snippet of code in
order to create unique passwords of 8 chars?
Many thanks in advance.
max
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net