I have a script to register a name, email address, and give a random generated password at sign up. The user then can login only using that generated password. I want to be able to let the user login and change the password when he/she wants to. Eventually I want the users to be able to update their other information but for now the password change is needed.
here is what I have so far for changing the password.
<?
include 'db.php';
$oldpasspass = $_POST["oldpasspass"];
$newpass = $_POST["newpass"];
$newpass2 = $_POST["newpass1"];
if ((!$oldpasspass) || (!$newpass) || (!$newpass2)) {
echo "You forgot to enter some of the required information.";
if (!$oldpasspass) {
echo "You have to enter an old password!";
}
if (!$newpass) {
echo "You have to enter a new password!";
}
if (!$newpass2) {
echo "You have to retype your new password!";
}
exit();
}
if (($newpass) != ($newpass2)) {
die("Your new passwords don't match!");
}
$password = $newpass;
$decrypted_pass = $newpass;
$password = md5($password);
$username = $_SESSION['username'];
// connect to database
$query = mysql_query("UPDATE users SET password='$password')
WHERE username='$username'");
if ($result = mysql_query($query)){
echo "password changed<br>";
} else {echo "error changing password";}
?>
I don't think this code is recognizing what user is logged in........and when I put the correct passwords in the text boxes it will always show every error message combined. If I type the correct old pass word, put two different passwords in for the new password it will still give me the error that I need to enter an old password.........I don't think it will ever give me "password changed" it cant get past the error messages
I would also like to compare the old password with the password that is in the database to make sure the user has the correct old password...............
can anyone please guide me in the right direction?