本文介绍了在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中加密密码?
发布评论