Jump to content

change password problem with the code


cryptonim

Recommended Posts

hi folks I have a problem with the code to change the password, it shows the message all time when  I send the form:  old password dont match!

 

<?php
session_start();

$user = $_SESSION['first_name'];

if ($user)

{
//user is logged in

if ($_POST['submit'])
{
	//check fields

	$oldpassword = md5($_POST['oldpassword']);
	$newpassword = md5($_POST['newpassword']);
	$repeatnewpassword = md5($_POST['repeatnewpassword']);

//check password against db
//connect db
$connect = mysql_connect("*******","****","****") or die("");

mysql_select_db("****") or die("");

$queryget = mysql_query("SELECT password FROM users WHERE username='$user'") or die("Query didnt work !!!");

$row = mysql_fetch_assoc($queryget);

$oldpassworddb = $row['password'];	

//check password
if ($oldpassword==$oldpassworddb)
{
		//check to new password
		if ($newpassword==$repeatnewpassword)
		{
		  //success
		  //change password in db
		  $querychange = mysql_query("UPDATE users SET password='$newpassword' WHERE username='$user'") or die ("");
		  
		  session_destroy();
		  
		  die("YOUR PASSWORD HAS BEEN CHANGED.<a href='login_form.html'>RETURN</a> TO THE LOGIN PAGE");
		  
		}
		else
		     			
		    die("new password dont match");

}
else 
   
      die("old password dont match");

}
 else
 {

echo"
<form action='changepassword.php' method='POST'>
Old password: <input type='text' name='oldpassword'><br/>
New password: <input type='password' name='newpassword'><br/>
Repeat new password: <input type='password' name='repeatnewpassword'><br/>
<input type='submit' name='submit' value='change password'>	
</form>";
 }
}
else
    echo("YOU MUST BE LOGGED IN!!!!.<br><a href='login_form.html'>RETURN</a> TO THE LOGIN PAGE");



?>

 

please help thx!

Link to comment
Share on other sites

Put queries inside variables as you can echo them out indivdually to debug. Do this :P.

 

Go through your code and echo variables at certain points to check and make sure they are what you expected.

Since this condition is never true (as you always get that message): $oldpassword==$oldpassworddb then there is a problem with the DB or how you are interacting with it.

 

hope this helps

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.