password_hash returns NULL

一世执手 提交于 2019-12-05 19:23:15
v010dya

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.

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.

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