为什么我的旧密码不会更改为新密码

时间:2014-01-07 07:32:57

标签: php mysql sql

这是我的会员表,密码全部在md5

ID username password
100  alex     alex

这是我的changepassword.php

<?php
session_start();

$conn = mysql_connect("localhost","root","password");
mysql_select_db("lecturer",$conn);
$myid = $_GET["myid"];
if(count($_POST)>0) {
  $result = mysql_query("SELECT * from members WHERE ID=' . $myid . '");
  $row=mysql_fetch_array($result);
  if (md5($_POST["currentPassword"]) == md5($row["password"])) {
    mysql_query("UPDATE members set password='" . $_POST["newPassword"] . "' WHERE ID=' . $myid . '");
    $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>

当我输入ID = 100并且我想将密码alex更改为alex123但我仍然得到我当前的密码不正确。 我在代码中做错了什么???

谢谢

1 个答案:

答案 0 :(得分:1)

仅使用

  

==($ row [“password”])){

因为您存储的密码已经编码