Re: Random Password problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux