简体   繁体   English

PHP md5()提供与MySQL md5不同的输出

[英]PHP md5() gives different output then MySQL md5

I'm trying to set up a login system, but I can't solve one problem: PHP is giving me an other output with md5(); 我正在尝试建立一个登录系统,但我无法解决一个问题:PHP正在给我一个md5()的其他输出; than MySQL... 比MySQL ...

For example, in PHP: 例如,在PHP中:

$password = md5("brickmasterj");
return $password;

Returns: 返回:

3aa7b18f304e2e2a088cfd197351cfa8

But the MySQL equivalent gives me a shorter version: 但MySQL等价物给了我一个更短的版本:

3aa7b18f304e2e2a08

What's the problem? 有什么问题? And how do I work with this while checking passwords? 在检查密码时如何使用它?

我猜你的表的列长度有问题,将密码字段的长度设置为至少32

No way MySQL returns it of a length of < 32. If you would do a simple query like SELECT md5('brickmasterj') , you would see. 没有办法MySQL返回长度<32的情况。如果你要做一个像SELECT md5('brickmasterj')这样的简单查询,你会看到。 Now you are most likely inserting the value into a column which is not wide enough. 现在,您很可能将值插入到不够宽的列中。

Is your database field 32 characters long? 您的数据库字段是否长32个字符? Are you writing to the database using mysql's md5? 你使用mysql的md5写入数据库吗?

The hash size if always fixed. 哈希大小如果总是固定的话。 In your case the hash size is 128 bits. 在您的情况下,散列大小为128位。 When converted to a ascii string it would be a 32 character string that contains only hexadecimal digits. 转换为ascii字符串时,它将是一个仅包含十六进制数字的32个字符的字符串。 so if you are storing variable character the length should be atleast 32 example: password varchar(32) should go in mysql table then you can call using php using select password from table where password =md5($password); 因此,如果你存储变量字符长度应该是至少32例子: password varchar(32)应该进入mysql表然后你可以使用php使用select password from table where password =md5($password);调用select password from table where password =md5($password);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM