【问题标题】:how PHP password_hash() determine using which algorithm by PHP_DEFAULT?PHP password_hash() 如何通过 PHP_DEFAULT 确定使用哪种算法?
【发布时间】:2018-11-14 17:21:13
【问题描述】:

阅读 PHP 文档时我感到很困惑
http://php.net/manual/en/password.constants.php
PASSWORD_DEFAULT (integer)
如果未提供算法,则用于散列的默认算法。当支持更新、更强的散列算法时,这可能会在更新的 PHP 版本中发生变化。

我如何知道我的安装使用了哪种算法?
我可以从 phpinfo() 中知道吗?
我可以控制默认值吗?

【问题讨论】:

标签: php password-protection password-hash


【解决方案1】:

我怎么知道我的安装使用了哪种算法?

查看手册。

从您引用的页面:

此常量的值:

  • PHP 5.5.0 - PASSWORD_BCRYPT

我可以从 phpinfo() 中知道吗?

否(嗯,除了使用它作为了解您正在使用的 PHP 版本然后与手册交叉引用的机制之外)。


我可以控制默认值吗?

不分叉 PHP 并编译您自己的版本。

【讨论】:

  • 昆汀,在这个答案中添加一些关于 password_needs_rehash() 的内容可能也很有用
  • 您也可以只散列一个虚拟字符串并读取结果的前几个字符以确定使用的算法,而不是检查 php 版本
【解决方案2】:

您无需担心默认使用哪种算法。 password_hash() 结果的前四个字符表示使用了哪种算法。当您使用password_verify() 时,它将自动确定算法。

【讨论】:

  • 请注意,如手册所述:. Therefore you should be aware that the length of the resulting hash can change. Therefore, if you use PASSWORD_DEFAULT you should store the resulting hash in a way that can store more than 60 characters (255 is the recomended width).
猜你喜欢
  • 1970-01-01
  • 2016-06-11
  • 2012-04-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-06
相关资源
最近更新 更多