PHP password_needs_rehash() 函数

PHP 教程 · 2019-01-31 23:26:47

password_hash() 函数用于检测散列值是否匹配指定的选项。

PHP 版本要求: PHP 5 >= 5.5.0, PHP 7

语法

bool password_needs_rehash ( string $hash , int $algo [, array $options ] )

参数说明:

  • hash: 一个由 password_hash() 创建的散列值。
  • algo: 一个用来在散列密码时指示算法的密码算法常量。
  • options: 一个包含有选项的关联数组。目前支持两个选项:salt,在散列密码时加的盐(干扰字符串),以及cost,用来指明算法递归的层数。这两个值的例子可在 crypt() 页面找到。 省略后,将使用随机盐值与默认 cost。

返回值

此函数检测指定的散列值是否实现了提供的算法和选项。 如果没有,需要重新生成散列值。

实例

password_needs_rehash() 用法

<?php $password = 'rasmuslerdorf'; $hash = '$2y$10$YCFsG6elYca568hBi2pZ0.3LDL5wjgxct1N8w/oLR/jfHsiQwCqTS'; // 当硬件性能得到改善时,cost 参数可以再修改 $options = array('cost' => 11); // 根据明文密码验证储存的散列 if (password_verify($password, $hash)) { // 检测是否有更新的可用散列算法 // 或者 cost 发生变化 if (password_needs_rehash($hash, PASSWORD_DEFAULT, $options)) { // 如果是这样,则创建新散列,替换旧散列 $newHash = password_hash($password, PASSWORD_DEFAULT, $options); } // 使用户登录 } ?>

点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html

查看所有标签

Host Your Web Site In The Cloud

Host Your Web Site In The Cloud

Jeff Barr / SitePoint / 2010-9-28 / USD 39.95

Host Your Web Site On The Cloud is the OFFICIAL step-by-step guide to this revolutionary approach to hosting and managing your websites and applications, authored by Amazon's very own Jeffrey Barr. "H......一起来看看 《Host Your Web Site In The Cloud》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具