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

查看所有标签

Artificial Intelligence

Artificial Intelligence

Stuart Russell、Peter Norvig / Pearson / 2009-12-11 / USD 195.00

The long-anticipated revision of this #1 selling book offers the most comprehensive, state of the art introduction to the theory and practice of artificial intelligence for modern applications. Intell......一起来看看 《Artificial Intelligence》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

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

URL 编码/解码

MD5 加密
MD5 加密

MD5 加密工具