我的网站上有一个页面,允许用户更改密码
该表格要求输入用户名、当前密码、新密码、确认新密码。
如果用户输入了错误的用户名,表单将不会更改他们的密码。
但是,如果用户输入了错误的密码,表单无论如何都会更改他们的密码。
我的代码贴在下面,如果有人可以提供帮助,我将不胜感激!谢谢!
约斯特
更改密码信息屏幕:
<div id="inlogscherm">
<form name="form1" method="post" action="changepw.php">
<div class="textm">Change password</div><br>
<div class="text">Username:</div><div class="invulbalkje"><? echo "{$_SESSION['myusername']}"; ?></div><br />
<input name="username" type="hidden" id="username" value="<? echo "{$_SESSION['myusername']}"; ?>">
<div class="text">Password:</div><input name="npassword" type="password" id="npassword" class="invulbalkje"><br />
<div class="text">New Password:</div><input name="newpassword" type="password" id="newpassword" class="invulbalkje"><br />
<div class="text">Repeat New Password:</div><input name="repeatnewpassword" type="password" id="repeatnewpassword" class="invulbalkje"><br />
<input type="submit" name="Submit" value="Change" class="button">
</form>
</div>
这是更改的 php。(changepw.php)
<?php
session_start();
$host="localhost";
$username=",";
$password=",";
$db_name=",";
$tbl_name=",";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$username = $_POST['username'];
$password = $_POST['password'];
$newpassword = $_POST['newpassword'];
$repeatnewpassword = $_POST['repeatnewpassword'];
$encrypted_password=md5($password);
$encrypted_newpassword=md5($newpassword);
$result = mysql_query("SELECT password FROM $tbl_name WHERE username='$username' and password = '$encrypted_password'");
if(!$result)
{
header("location:error1.php");
}
if(mysql_num_rows($result)){
if($newpassword==$repeatnewpassword){
$sql=mysql_query("UPDATE $tbl_name SET password='$encrypted_newpassword' where username='$username'");
if($sql)
{
header("location:success.php");
}
else
{
header("location:error3.php");
}
} else {
header("location:error_password_not_matched.php");
}
} else {
header("location:error.php");
}
?>
如果您看到问题,请与我联系。我将非常感谢!