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

查看所有标签

The Haskell School of Music

The Haskell School of Music

Paul Hudak、Donya Quick / Cambridge University Press / 2018-10-4 / GBP 42.99

This book teaches functional programming through creative applications in music and sound synthesis. Readers will learn the Haskell programming language and explore numerous ways to create music and d......一起来看看 《The Haskell School of Music》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器