PHP:从MD5更新密码

时间:2014-12-31 10:11:43

标签: php select hash sql-update md5

我从MD5更新密码时遇到问题我没有收到任何错误,但是他们没有更新! 这是我的代码..我在Stackoverflow中看到了有关MD5的问题。并添加更多行但不幸的是我无法更新我的密码。我知道很多问题,但我找不到它们

<?php


$_SESSION["sess_user"] = "24";
include "config.php";
mysql_select_db("user_registration",$con);

if(isset($_POST['submit']))
{
$cur_password=$_POST['currentPassword'];

if(count($_POST)>0) {
$result = mysql_query("SELECT * FROM users WHERE id ='" . $_SESSION["sess_user"] .  "' AND passwords = '".MD5($cur_password)."'");
$row=mysql_fetch_array($result);
if($row['passwords'] == MD5($cur_password)) {
mysql_query("UPDATE users SET passwords ='" . md5($_POST["newPassword"]) . "' WHERE id ='" . $_SESSION["sess_user"] . "'");
$message = "Password Changed";
} else $message = "Current Password is not correct";
}
}
?>
<html>
<head>
<title>Change Password</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
<script>
function validatePassword() {
var currentPassword,newPassword,confirmPassword,output = true;

currentPassword = document.frmChange.currentPassword;
newPassword = document.frmChange.newPassword;
confirmPassword = document.frmChange.confirmPassword;

if(!currentPassword.value) {
    currentPassword.focus();
    document.getElementById("currentPassword").innerHTML = "required";
    output = false;
}
else if(!newPassword.value) {
    newPassword.focus();
    document.getElementById("newPassword").innerHTML = "required";
    output = false;
}
else if(!confirmPassword.value) {
    confirmPassword.focus();
    document.getElementById("confirmPassword").innerHTML = "required";
    output = false;
}
if(newPassword.value != confirmPassword.value) {
    newPassword.value="";
    confirmPassword.value="";
    newPassword.focus();
    document.getElementById("confirmPassword").innerHTML = "not same";
    output = false;
}   
return output;
}
</script>
</head>
<body>
<form name="frmChange" method="post" action="" onSubmit="return validatePassword()">
<div style="width:500px;">
<div class="message"><?php if(isset($message)) { echo $message; } ?></div>
<table border="0" cellpadding="10" cellspacing="0" width="500" align="center" class="tblSaveForm">
<tr class="tableheader">
<td colspan="2">Change Password</td>
</tr>
<tr>
<td width="40%"><label>Current Password</label></td>
<td width="60%"><input type="password" name="currentPassword" class="txtField"/><span id="currentPassword"  class="required"></span></td>
</tr>
<tr>
<td><label>New Password</label></td>
<td><input type="password" name="newPassword" class="txtField"/><span id="newPassword" class="required"></span></td>
</tr>
<td><label>Confirm Password</label></td>
<td><input type="password" name="confirmPassword" class="txtField"/><span id="confirmPassword" class="required"></span></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Submit" class="btnSubmit"></td>
</tr>
</table>
</div>
</form>
</body></html>

0 个答案:

没有答案