RE: [PHP] Random letter/number passwords
| From: | Matt Stone | Date: | Mon, 26 Mar 2001 06:14:41 +0000 |
| Subject: | RE: [PHP] Random letter/number passwords | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-45580@lists.php.net to get a copy of this message | ||
Oops sorry, this line is supposed to read:
$passfirst = randomGen($length-3, 1);
>>$passend = randomGen(3, 0);
$pass = $passfirst.'-'.$passend;
return $pass;
-----Original Message-----
From: Matt Stone [mailto:matt@planetveggie.com]
Sent: Monday, 26 March 2001 4:12 PM
To: PHPlist
Subject: [PHP] Random letter/number passwords
Hi,
I have this code below which is supposed to be generating a password like
QCCQCN2-IUZ with 10 characters - All but three in the first section (7) and
three in the last part - but does not work in all cases. Sometimes it prints
LPSA3WD-IM or G22G2G9-FC.
Is there a catch in the code that will stuff up in certain circumstances?
Please help,
Matt stone
____________________________________________________________________________
_______
<?php
function randomGen($length, $status) {
$all = explode( " ",
"A B C D E F G H I J K L M N O P Q R S T U V W X Y Z "
. "0 1 2 3 4 5 6 7 8 9");
$allend = explode( " ",
"A B C D E F G H I J K L M N O P Q R S T U V W X Y Z");
for($i=0;$i<$length;$i++) {
srand((double)microtime()*time());
$randy = (($status)? rand(0, count($all)) : rand(0, count($allend)));
$pass .= (($status)? $all[$randy] : $allend[$randy]);
}
return $pass;
}
function randomPassword($length = 8) {
$passfirst = randomGen($length-3, 1);
$passend = randomGen(4, 0);
$pass = $passfirst.'-'.$passend;
return $pass;
}
for($i;$i<10;$i++){
$new_random = randomPassword(10);
echo "$new_random<br>";
}
?>
--
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