Jump to content

Recovered Passwords do not update in database


MrXortex

Recommended Posts

Hello.

I created a little recover page. Users write the email and a random password is sent to them. The random password is successfully send in their emails but when they login with the new password it doesn't login. I think the new password does not updates in my database. How do I fix this issue?

Heres the code: (avandare or avandaramn means 'users' in swedish

if(isset($_POST['submit']) && $inLoggad == false){
	
	//storing the posted info in variables
	
	$email = mysql_real_escape_string($_POST['email']);
	
	$exist = mysql_fetch_array( mysql_query("SELECT * FROM anvandare WHERE email='$email' LIMIT 1") );
	
	if($exist['email'] == $email){
		
		//creating a new generated password for the user, if the user has forgotten
		$newPwd = genPassword();
		$newHashPwd = md5($newPwd);
		
		//send the new generated password via email of the user
		$message = "Hello " . $exist['anvandarnamn'] . ". Your new password is: " . $newPwd;
		$mailheader = "From: HighPload";   
		$mailheader .= "Reply-To: noreply@noreply.com";   
		$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
		mail($exist['email'],  "HighPload - Your new password has arrived!", $message, $mailheader) or die($fail = true); 
		
		//Updating the new password in the dB
		if($fail != true){
			mysql_query("UPDATE anvandare SET password='$newHashPwd' WHERE email='$email' ");
		}
	}else {
		$showErrors = true;
	}
	
	
}
elseif($inLoggad == true) {
	print '<script>window.location = "index.php"</script>';
}

?>

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.