password_hash returns NULL

谁说胖子不能爱 提交于 2019-12-10 09:37:42

问题


How come the documentation states that password_hash can return either a string or value false, but the following line of code returns NULL?

$password = password_hash($password1, PASSWORD_BDCRYPT, array( 'cost' => 10 ));

回答1:


Despite the fact that it is not documented, the function does return NULL when one provides an incorrect value for algorithm.

Currently supported constants are:

  • PASSWORD_BCRYPT
  • PASSWORD_DEFAULT

And a typo in this case (PASSWORD_BDCRYPT rather than PASSWORD_BCRYPT) results in the value of NULL being passed, that in turn causes the same value as the return.


Edit: Any other string that has not been defined before would also evaluate as NULL.




回答2:


As said before, incorrect parameter results in NULL being returned. Just to be complete: note that this goes not for just incorrect algorithm number, but also for providing incorrect $options parameter - e.g. calling:

password_hash('something', PASSWORD_DEFAULT, 10);

will also return NULL with no other error.



来源:https://stackoverflow.com/questions/32226295/password-hash-returns-null

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