i found this somewhere here and tried to make use of it. thanks. but i am having problems.
1) when user inputs new password and on the retype puts a different password, it echoes "Your new passwords don't match"
but still updates the database!(with the value on the input on new), and echoes "password changed". what i want is when there is no match between them, the database should not be updated!!! what's wrong here??? thanks.
<?
$old = $_POST["oldpass"];
$new = $_POST["newpass"];
$new2 = $_POST["newpass1"];
if ((!$old) || (!$new) || (!$new2)) {
echo "You forgot to enter some of the required information.";
if (!$old) {
echo "You have to enter an old password!";
}
if (!$new) {
echo "You have to enter a new password!";
}
if (!$new2) {
echo "You have to retype your new password!";
}
exit();
}
if (($new) != ($new2)) {
echo "Your new passwords don't match!";
}
?>
<?
$password = $new;
$decrypted_pass = $new;
$password = md5($password);
$username = $_SESSION['username'];
// connect to database
include("connect.php");
$query = "UPDATE table SET
password='$password'
WHERE username='$username'";
if ($result = mysql_query($query)){
echo "password changed<br>";
} else {echo "error changing password";}
?>
p.s.
after they successfully changed their password, i want them also to be logged out and redirected to the login page and enter with their new password!