Note that there are some explanatory texts on larger screens.

plurals
  1. POChange Password script in PHP and MD5 hashing
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/8283653/forget-password-page-creating-a-generated-password-to-email-to-the-user">forget password page, creating a generated password to email to the user.</a> </p> </blockquote> <p>I am trying to create a change password page. The code below should check to make sure the user is in the database, confirm there current password and allow them to change their password. It validates their new password correctly checking to make sure they are the same and a certain length, but it does not return an error message if the user name is not in the database and it says that the current password to a user that is in the database is wrong. I think it is not matching the hash passwords correctly but I am not sure. Can anyone help me fix these problems. Thanks. </p> <pre><code>&lt;!-- To change this template, choose Tools | Templates and open the template in the editor. --&gt; &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt; &lt;title&gt;Change Password Confrim&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;?php $db_server = "server"; $db_username = "name"; $db_password = "pass"; $con = mysql_connect($db_server, $db_username, $db_password);if (!$con) { die('Could not connect: ' . mysql_error()); } $database = "User"; $er = mysql_select_db($db_username); if (!$er) { print ("Error - Could not select the database"); exit; } //////////Collect the form data //////////////////// $username =$_P0ST['username']; $cur_password=$_POST['cur_password']; $password=$_POST['password']; $password2=$_POST['password2']; ///////////////////////// $password = mysql_real_escape_string($password); $password2 = mysql_real_escape_string($password2); $username = mysql_real_escape_string($username); $cur_password = mysql_real_escape_string($cur_password); //Setting flags for checking $status = "OK"; $msg=""; //Checking to see if password is at least 3 char max 8 if ( strlen($password) &lt; 3 or strlen($password) &gt; 15 ) { $msg=$msg."Password must be more than 3 char legth and maximum 15 char lenght&lt;br/&gt;"; $status= "NOTOK"; } //Checking to see if both passwords match if ( $password &lt;&gt; $password2 ) { $msg=$msg."Both passwords are not matching&lt;br/&gt;"; $status= "NOTOK"; } $CorrectUser = mysql_query("SELECT * FROM User WHERE username ='$username' AND password = MD5('$cur_password')"); $row = mysql_fetch_array($CorrectUser); if ($row['username'] == $username) { $status = "OK"; } else { print("Your username is not in the database. Please check that you enter the correct username and try again."); $status = "NOTOK"; } if ($row['cur_password'] == MD5('$cur_password')) { $status = "OK"; } else { print("You entered the wrong current passowrd"); $status = "NOTOK"; } if($status&lt;&gt;"OK"){ echo "&lt;font face='Verdana' size='2' color=red&gt;$msg&lt;/font&gt;&lt;br&gt;&lt;center&gt;&lt;input type='button' value='Retry' onClick='history.go(-1)'&gt;&lt;/center&gt;"; } else { // if all validations are passed. if(mysql_query("UPDATE User SET password = MD5('$password') WHERE username ='$username'")) { echo "&lt;font face='Verdana' size='2' &gt;&lt;center&gt;Thanks &lt;br&gt; Your password changed successfully.&lt;/font&gt;&lt;/center&gt;"; } else { echo "&lt;font face='Verdana' size='2' color=red&gt;&lt;center&gt;Sorry &lt;br&gt; Failed to change password.&lt;/font&gt;&lt;/center&gt;"; } } ?&gt; &lt;center&gt; &lt;br&gt;&lt;br&gt;&lt;a href='Settings.html'&gt;Settings Page&lt;/a&gt;&lt;/center&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload