gpt4 book ai didi

php - 为什么我的旧密码无法更改为新密码

转载 作者:行者123 更新时间:2023-11-29 13:20:04 29 4
gpt4 key购买 nike

这是我的成员(member)表,密码全部为 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,但我不断收到当前密码不正确的信息。我的代码做错了什么???

谢谢

最佳答案

仅使用

== ($row["password"])) {

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

关于php - 为什么我的旧密码无法更改为新密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20966271/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com