使用 MD5 更改密码形式?
我有更改用户密码的 php 代码。但是在我尝试了代码之后...提交新密码时..新密码在sql数据库中显示...我希望它是md5代码密码。你能用我的代码解决这个问题吗
if($_REQUEST['do'] == 'edit')
{
$title = 'change password';
$page = $_POST['page'];
$userId = safe($_POST['userId']);
$passwd = safe($_POST['password']);
$email = safe($_POST['Email']);
$passw2 = $_POST['password2'];
if(md5($passwd) == $_SESSION['user']['password'])
{
if(empty($passw2))
{
$pass = $_SESSION['user']['password'];
}
else
{
$pass = $passw2;
}
$query = $db->query("UPDATE users SET email = '".$email."' , password = '".$pass."' WHERE Id = '".$userId."' ");
if($query)
{
$msg = "password changed successfully";
}
I have the php code for changing user password. but after I tried the code... when submitting the new password.. the new password became revealed in the sql database ... I want it to be in md5 code password. can you please fix the problem with my code
if($_REQUEST['do'] == 'edit')
{
$title = 'change password';
$page = $_POST['page'];
$userId = safe($_POST['userId']);
$passwd = safe($_POST['password']);
$email = safe($_POST['Email']);
$passw2 = $_POST['password2'];
if(md5($passwd) == $_SESSION['user']['password'])
{
if(empty($passw2))
{
$pass = $_SESSION['user']['password'];
}
else
{
$pass = $passw2;
}
$query = $db->query("UPDATE users SET email = '".$email."' , password = '".$pass."' WHERE Id = '".$userId."' ");
if($query)
{
$msg = "password changed successfully";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
替换
为
Replace
with
$_SESSION['user']['password'] 被(假设)编码为 MD5,但从用户表单中获取的 passw2 是普通的。
您需要更改
为
在将密码提交到数据库之前, 将密码编码为 md5。
并且使用新密码更改 $_SESSION['user']['password'] 或用户在同一会话中只能更改一次密码。
The $_SESSION['user']['password'] is (is suppoused) encoded as MD5 but the passw2 fetched from the user form is plain.
you need to change
by
to enconde as md5 the password before submit it to the database.
And also change the $_SESSION['user']['password'] with the new password or the user can change only one time the password in the same session.