RE: [PHP-DB] Random Password problem
| From: | Bastien Koert | Date: | Tue, 08 Mar 2005 20:14:03 +0000 |
| Subject: | RE: [PHP-DB] Random Password problem | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-38826@lists.php.net to get a copy of this message | ||
and my version
function change_password($id, $password)
{
//generate a random password
$pass = "";
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
$i = 0;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($salt, $num, 1);
$pass = $pass . $tmp;
$i++;
}
//change the password in the db
$sql = "update cust_info set cust_pw ='".md5($pass)."', temp_pass = 1 where cust_lg = '$id' and cust_pw = '$password'";
$result = connect($sql);
if ($result){
return $pass;
}else{
change_password($id, $password);
}
bastien
From: "Wendell Frohwein" <wendell@3rdpixel.com> To: "'J. Connolly'" <web@jozef.info>,"'PHP list'" <php-db@lists.php.net> Subject: RE: [PHP-DB] Random Password problem Date: Tue, 8 Mar 2005 11:51:59 -0800 This is one I like to use jozef. function generate_password($length = 10) { $allowable_characters = "abcdefghjkmnopqrstuvwxyz23456789"; $ps_len = strlen($allowable_characters); mt_srand((double)microtime()*1000000); $pass = ""; for($i = 0; $i < $length; $i++) { $pass .= $allowable_characters[mt_rand(0,$ps_len-1)]; } return $pass; } Its been working well for me for sometime. -Wendell Frohwein -----Original Message----- From: J. Connolly [mailto:web@jozef.info] Sent: Tuesday, March 08, 2005 11:41 AM To: PHP list Subject: [PHP-DB] Random Password problem 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); $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 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 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php