在PHP中转换为md5是错误的 [英] convert to md5 is wrong in php

查看:160
本文介绍了在PHP中转换为md5是错误的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要从用户那里获取用户名和密码的表格, 我将密码转换为md5.然后将其插入数据库.在用户登录表单中,我获取密码并将其转换为md5.然后,我比较两个密码.它在某些情况下匹配,但是如果password = p@$$w0rd则失败. 有什么问题?那么该问题的解决方案是什么?

I have a form in which I am taking username and password from user, and I am converting the password to md5. Then I insert it into database. In user login form, I take the password and convert it to md5. Then I compare both passwords. It matches in some condition but fails if password = p@$$w0rd. What is the issue ? And what is the solution for this issue?

从我的表单到p@$$w0rd的数据库密码到md5为b7463760284fd06773ac2a48e29b0acf,从登录表单为e22bb24ca616331cb92a48b712034bc3

From my form to database password of p@$$w0rd to md5 is b7463760284fd06773ac2a48e29b0acf and from login form it is e22bb24ca616331cb92a48b712034bc3

注册表格中的代码

$password = trim($_POST['password']);   
$dpassword = md5($password);

并且从登录表单 $passwd = md5($password);

$sql = mysql_query("select * from create_dealer where (dealer_email='$user' && password='$passwd')");

推荐答案

问题出在引号上.

echo md5('p@$$w0rd');// echoes b7463760284fd06773ac2a48e29b0acf
echo md5("p@$$w0rd");// echoes e22bb24ca616331cb92a48b712034bc3

使用双引号时,$w0rd被视为未定义变量,并替换为空字符串.

When you use double quotes, $w0rd is considers as an undefined variable and replaced with an empty string.

echo md5("p@$");// echoes e22bb24ca616331cb92a48b712034bc3

这篇关于在PHP中转换为md5是错误的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆