Re: Random Password problem

From: Date: Wed, 09 Mar 2005 07:40:51 +0000
Subject: Re: Random Password problem
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-38828@lists.php.net to get a copy of this message
J. Connolly wrote:
I am using this php in order to create, store and send random passwords to people who want to join my mailing list. <?php function random_password () { $seed = (integer) md5(microtime()); mt_srand($seed);
your seeding the randomizer with the value zero each time! the expression: (integer) md5(microtime()) is (almost) always going to equal zero (unless it happens to start with one or more numeric chars). basically get rid of the code that seeds the randomizer, unless your using a really old version of php, because you don't need to seed the randomizer at all. if you remove the line: mt_srand($seed); your passwords will drastically increase in 'randomness'
$password = mt_rand(1,99999999); $password = substr(md5($password), 3,9); return $password; } ?> <?php $msg = random_password(); echo $msg; ?> I seem to be getting the same number very often which makes me fear that
"fear causes hesitation, hestitation causes your worse fears to come true....." (yadda yadda, that film is sooooooo pre-Matrix ;-)
this is not so random. I am a noob so I do not know if this is coincidence or a fault in my coding. Right now, I have been setting up passwords manually, but would like users to be as free from me as possible. Any direction would be helpful. BTW, I keep getting the following number an absurd amount of times. I have deleted cookies and even gone to other machines, and yet it still generates this number. 8f31a3 Thank you, jozef


« previous php.db (#38828) next »