Re: Number/Letter Passwords

From: Date: Wed, 28 Mar 2001 07:06:41 +0000
Subject: Re: Number/Letter Passwords
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-45840@lists.php.net to get a copy of this message
""Matt Stone"" <matt@planetveggie.com> wrote in message news:APEOJFGLJFFCMFFNIGLMMECPCHAA.matt@planetveggie.com... > Hi,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 > define(FIRST_STR,1); > define(LAST_STR,0); > > function randomGen($length, $mode) { > $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 = (($mode)? rand(0, count($all)) : rand(0, count($allend))); Count returns number of elements in array, so you should substrct 1. i.e. $randy = (($mode)? rand(0, count($all)-1) : rand(0, count($allend)-1)); Then should work all the time. Regards, -- Yasuo Ohgaki

« previous php.general (#45840) next »