Hi all,
This is my chage password script. This works ONLY if all the data fields entered correctly. Otherwise it gives several error messages. (Ex:incorrect username, incorrect pw etc)
users (user_id, first_name,last_name, email, phone_number, user_type, username, password)
<?php
session_start();
$connection=mysql_connect("localhost","root","");
$db=mysql_select_db("bank",$connection);
$username = $_POST['username'];
$password = $_POST['password'];
$newpassword = $_POST['newpassword'];
$newpassword = md5($newpassword);
$confirmnewpassword = $_POST['confirmnewpassword'];
$confirmnewpassword = md5($confirmnewpassword);
$result = mysql_query("SELECT password FROM users WHERE username='$username'");
if(!$result)
{
echo "The username you entered does not exist";
}
else
if(md5($password)!=mysql_result($result,0))
{
echo "You entered an incorrect password";
}
if($newpassword==$confirmnewpassword)
$sql=mysql_query("UPDATE users SET password='$newpassword' where username='$username'");
if($sql)
{
echo "Congratulations You have successfully changed your password";
}
else
{
echo "The new password and confirm new password fields must be the same";
}
?>