PHP: change password
711
I am implementing a password change function for my website. Unofortunately it doesn't work.
In the .html file I got the code:
<form method='post' >
<td>Old Password:</td>
<td><input name='oldpw' type='password' required='required'/></td>
<tr>
<td>New Password:</td>
<td><input name='newpw' type='password' required = 'required' /></td>
<tr>
<td>Confirm Password:</td>
<td><input name='conpw' type='password' required = 'required' /></td>
<td>
<input type='submit' value='Change Password' />
</td>
</tr>
</form>
In the account.php file I wrote this:
if (isset($_POST['newpw'])){
$pw=$dbc->query("select passwort from kundenaccount where accname= '" . $_SESSION['accname'] . "';")
$row = $pw->fetch_object()
$pawo = $row->passwort
if (md5($_POST['oldpw']) == $pawo){
if ($_POST['newpw']==$_POST['conpw']){
$dbc->query("UPDATE accname SET passwort='" . md5($_POST['newpw']) . "' WHERE accname='" . $_SESSION['accname'] . "';")
}
else { echo "Passwords do not match" }
}
else { echo "Wrong password entered"}
}
Do anyone see my mistake? I try to solve this problem since days..
Hope anyone can help.
Thanks
Answer
Solution:
Try this on your form:
UPDATE:
I went through and made the script for my database, works fine. change values where needed:
Answer
Solution:
should be
Answer
Solution:
md5 is a one way hash so you cannot undo it, you should compare the other way.
NOTE: MD5 is not considered secure, I would upgrade to some other algorithm..
Answer
Solution:
Another solution to the problem