在md5中加密密码?

编程入门 行业动态 更新时间:2024-10-26 22:22:49
本文介绍了在md5中加密密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可能重复: 需要帮助…如何将md5添加到密码字段在php中?

Possible Duplicate: Need help… how to add md5 to password field in php?

我有这个脚本,允许用户更改密码.但是我想用"md5"将"newpassword"加密到数据库中.谁能告诉我如何更改此脚本以加密md5中的"newpassword"?

I have got this script to allow users to change their passwords. But am wanting the 'newpassword' to be encrypted into the database with md5. Can anyone tell me how i can change this script to encrypt the 'newpassword' in md5 please?

<?php require_once("session.php"); require_once("functions.php"); require('_config/connection.php'); ?> <?php session_start(); include '_config/connection.php'; $email = $_POST['email']; $password = $_POST['password']; $newpassword = $_POST['newpassword']; $confirmnewpassword = $_POST['confirmnewpassword']; $result = mysql_query("SELECT password FROM ptb_users WHERE email='$email'"); if(!$result) { echo "The username you entered does not exist"; } else if($password!= mysql_result($result, 0)) { echo "You entered an incorrect password"; } if($newpassword=$confirmnewpassword) $sql=mysql_query("UPDATE ptb_users SET password='$newpassword' where email='$email'"); if($sql) { echo "Congratulations You have successfully changed your password"; } else { echo "The new password and confirm new password fields must be the same"; } ?>

推荐答案

您正在根据纯文本字符串检查数据库的md5密码,您必须在执行此检查之前将密码转换为md5.例子

You are checking the database's md5 password against plain text string, you have to convert the password to md5 before you do this check. Example

else if(md5($password)!= mysql_result($result, 0)) { echo "You entered an incorrect password"; } if($newpassword=$confirmnewpassword) $newpassword = md5($newpassword); $sql=mysql_query("UPDATE ptb_users SET password='$newpassword' where email='$email'"); if($sql) { echo "Congratulations You have successfully changed your password"; } else { echo "The new password and confirm new password fields must be the same"; }

更多推荐

在md5中加密密码?

本文发布于:2023-10-24 23:58:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1525363.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:密码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!