在php中未更改密码。请检查代码
我已经在我的主页链接更改密码…现在我告诉你我在做什么在php中未更改密码。请检查代码,php,Php,我已经在我的主页链接更改密码…现在我告诉你我在做什么 首先,我创建了一个名为edit_profile.php的html表单,其中有三个文本框“旧密码”、“新密码”和“确认密码”。我将此页面作为更改密码主页的链接 下一页我将设计一个名为edit_profile1.php的页面,在这个页面中,我将比较新密码和确认密码是否相等 然后我用password=old password查询数据 但是这个页面不起作用。现在我给你两个文件的代码,最后我会告诉你我面临的类型错误 edit_profile.php
- 首先,我创建了一个名为edit_profile.php的html表单,其中有三个文本框“旧密码”、“新密码”和“确认密码”。我将此页面作为更改密码主页的链接
- 下一页我将设计一个名为edit_profile1.php的页面,在这个页面中,我将比较新密码和确认密码是否相等
- 然后我用password=old password查询数据
edit_profile.php
<?php
session_start();
?>
<html>
<body bgcolor="pink">
<table cellpadding="10" cellspacing="6" align="center" width="500">
<form name="form" action="edit_profile1.php" method="POST" >
<tr>
<td><b><i>Your Username</i></b></td>
<td><input type="text" name="username" id="username" size="30" maxlength="30" value="<?php echo $_SESSION['employee']['username']; ?>" disabled="disabled"></td>
</tr>
<tr>
<td><b><i>Old Password</i></b></td>
<td><input type="password" name="opassword" id="opassword" size="30" maxlength="30" value="" ></td>
</tr>
<tr>
<td><b><i>New Password</i></b></td>
<td><input type="password" name="npassword" id="npassword" size="30" maxlength="30" value="" ></td>
</tr>
<tr>
<td><b><i>Confirm Password</i></b></td>
<td><input type="password" name="cpassword" id="cpassword" size="30" maxlength="30" value="" ></td>
</tr>
<tr>
<td align="center" colspan="100"> <input type="submit" name="submit" value="Change Password"></td>
</tr>
</table>
</body>
</html>
edit_profile.php
您的用户名
您的脚本似乎容易受到mysql注入的攻击强>
对SQL查询中插入的每个值应用mysql\u real\u escape\u string
您的比较可能不起作用,因为从表单检索的值中有额外的空格。尝试:
$a=trim($_POST['opassword']); //old password value
$b=trim($_POST['npassword']); //new password value
$c=trim($_POST['cpassword']);
此外:
这是行不通的
您必须使用:
isset($_POST['opassword']) && isset($_POST['npassword'])
不应该
$query="select * from employee where Username='{$usr}' and Password='{$c}'";
是
相反?($a
而不是$c
)你的代码看起来很混乱。您应该使用比$a
、$b
和$c
更清晰的变量名!我试过了。很抱歉我写错了,但它也不起作用(正如上面@lamas所指出的,你应该转义你的所有数据。请继续阅读)你也需要散列$a,做一个$a=hash('sha1',$a);在查询之前,您上面的代码正在将明文$a与数据库中的加密密码进行比较。谢谢,先生,实际上我错了$a的哈希。非常感谢
isset($_POST['opassword']) && isset($_POST['npassword'])
$query="select * from employee where Username='{$usr}' and Password='{$c}'";
$a = hash('sha1', $a); // added after conversation in comments
$query="select * from employee where Username='{$usr}' and Password='{$a}'";