Crypt is different on server than on local machine

走远了吗. 提交于 2019-12-10 23:38:41

问题


I am developing an API using PHP (Codeigniter) and Phils RESTserver. I am creating a hash using crypt() with the password and the salt.

The problem is that the hash that is the result of the crypt() algorithm is different on my local machine and on the server.

It works fine locally but not on the server (to short). I know the password and the salt are the same because I tried them hardcoded to.

Hash from local machine:

$2a$10$g6J7CUjJvB0JpTd7UcrowePEbqp/oBmZEpd7vS.5HFYx38f08Tb/a

Hash from the server:

$2jkP2/LlC/H6

What can be wrong?

(server is running centos 5).


回答1:


Your PHP version probably does not support blowfish hashing for crypt. The $2a$ in the output suggests you're trying to use CRYPT_BLOWFISH which may not be available on both platforms.

http://uk.php.net/crypt

A bug was fixed in PHP 5.3.2:

Fixed Blowfish behaviour on invalid rounds to return "failure" string ("*0" or "*1"), instead of falling back to DES.

So i'd guess the hash from your server is falling back to DES, since it contains only the first 2 characters of your salt.



来源:https://stackoverflow.com/questions/7058627/crypt-is-different-on-server-than-on-local-machine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!