You can't. Its an MD5 hash, not an encryption...I reset the password to a random one, and email it to the user, also flag the account to force them to change the password upon login...

function mail_password()
global $err_msg;
//get the variables from the form
if ((isset($_POST['email']))&&(isset($_POST['lg_name']))){
$email = $_POST['email'];
$mid = $_POST['lg_name'];
$date_cookie = $_COOKIE['last_time'];
$err_msg = "<b>Please enter both your email address and your username. Thank you.</b>";
}//end if

//create the sql and run the query
$sql = "SELECT * FROM users WHERE user_email='$email' and user_name = '$mid'";

        $result = connect($sql);

//check the query results
if (mysql_num_rows($result)!=1){
$err_msg = "<font color=red>No results found. Please re-enter your username and email address to try again.</font>";


                $row = mysql_fetch_array($result);
                $email2 = $row['cust_email'];
                $pass   = $row['cust_pw'];

//call the change password function and pass it the information related to the record to create the temp password
$new_pass = change_password($mid, $pass);

                $sendto         = $email2;
                $from           = "WebMaster <[EMAIL PROTECTED]>";
                $subject        = "Forgotten Password";
                $message        = "Dear $email2,

                Your password is $new_pass.

                echo $message;

                $headers = "MIME-Version: 1.0\n";
                $headers .= "Content-type: text/plain; charset=iso-8859-1\n";
                $headers .= "X-Priority: 3\n";
                $headers .= "X-MSMail-Priority: Normal\n";
                $headers .= "X-Mailer: php\n";
                $headers .= "From: \"".$from."\" <".$from.">\n";

                if (!mail($sendto, $subject, $message, $headers)){
                        echo "Mail failed to send";
                }//end if
        }//end if
}//end function

// change password function
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);
}//end function


From: "moses Woldeselassie" <[EMAIL PROTECTED]>
Subject: [PHP-DB] MySQLPHP decrypt(password)
Date: Fri, 25 Feb 2005 10:20:55 +0000

hi all

I am using password() to crypt a user password online. but how do i decrypt a user password, when user forgot his/her password?

kind regards m

PHP Database Mailing List (
To unsubscribe, visit:

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

Reply via email to