Below is a code to reset forgoten password, but i do not know why i cannot login with the resetted password?
ps: echo $password is to get the echoed password so that i can login with it.
Thanks
<?php
if(isset($_POST['submit'])){
$email = addslashes(htmlentities($_POST['email']));
if($email == ''){
echo "<font color='#990000'><b><center>Email field empty</center></b></font>";
}
elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){
echo "<font color='#990000'><b><center>Invalid email address</center></b></font>";
}else{
$q = "SELECT * FROM reg_users WHERE email = '$email' AND username = '$_SESSION[uname]' AND Security_no = '$_SESSION[sec_no]'";
$r = mysql_query($q);
if(mysql_num_rows($r)== 1){
// Generate a random password
$password = "";
$alpha = array_merge(range('a','z'), range('A','Z'), range(2,9));
$rand_key = array_rand($alpha, 6);
foreach ($rand_key as $curKey){
$password .= $alpha[$curKey];
echo $password;
}
echo "<br><br>";
$crypt_pass = md5($password);
//update the user password
$q = "UPDATE reg_users SET password = '$crypt_pass' WHERE email = '$email' AND Security_no = '$_SESSION[sec_no]'";
$r = mysql_query ($q) or die('Cannot complete update');
//send mail
$to = "jamboree@yahoo.com"; //$_POST['email'];
$from = "forgot@example.com";
$subject = "New password";
$msg = "You recently requested that we send you a new password for fredcom.com. Your new password is: $password.\n
Please log in at this URL: http://localhost/login.html \n
Then go to this address to change your password: http://localhost/changepass.php";
$success = mail("$to","$subject","$msg","From: $from\r\nReply-To:webmaster@example.com");
if($success){
echo "Password have been sent to you email address";
}
}else{
echo "<font color='#990000'><b>Sorry, no such record in our databsae</b></font>";
}
}
}
?>













