and my version

function change_password($id, $password)
//generate a random password
$pass = "";
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
$i = 0;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($salt, $num, 1);
$pass = $pass . $tmp;
//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;
change_password($id, $password);


From: "Wendell Frohwein" <[EMAIL PROTECTED]>
To: "'J. Connolly'" <[EMAIL PROTECTED]>,"'PHP list'" <>
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);
  $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:[EMAIL PROTECTED]
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.

function random_password () {
$seed = (integer) md5(microtime());
$password = mt_rand(1,99999999);
$password = substr(md5($password), 3,9);
return $password;

$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.


Thank you,

PHP Database Mailing List (
To unsubscribe, visit:

PHP Database Mailing List (
To unsubscribe, visit:

-- PHP Database Mailing List ( To unsubscribe, visit:

Reply via email to