简体   繁体   English

PHP md5每次生成不同的哈希

[英]PHP md5 generating different hash each time

I have a form which is storing an md5 'ed password. 我有一个存储md5密码的表格。

For testing purposes I am using " 12345 " as a password. 为了进行测试,我使用“ 12345 ”作为密码。

To save the password I use: $password = md5($password); 要保存密码,我使用: $password = md5($password);

Using the same code and the same password the PHP is creating a different md5 hash everytime although I'm using the same password each time. 使用相同的代码和密码,PHP每次都会创建不同的md5哈希,尽管我每次都使用相同的密码。

Any ideas why this might be happening? 任何想法为什么会发生这种情况?

That's not possible with md5() , The hash will never change for a given text , It's definitely wrong with your implementation. 对于md5()这是不可能的,对于给定的文本,哈希值永远不会改变,这在实现上肯定是错误的。

The two cases of failure 失败的两种情况

  • Maybe you are passing the md5() hashed password as an argument to the md5() function again and again. 也许您一次又一次将md5()哈希密码作为参数传递给md5()函数。

  • There maybe some whitespace getting added to your $password . $password可能添加了一些空格。 Just trim() it as shown below. 只需将其trim()如下所示。

    $password = md5(trim($password));

    Remember : Even a space can change your hash. 切记 :即使一个空格也可以更改您的哈希。

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

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