首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

password_needs_rehash

(PHP 5 >= 5.5.0, PHP 7)

password_needs_rehash - 检查给定的散列是否与给定的选项匹配

描述

代码语言:javascript
复制
boolean password_needs_rehash ( string $hash , integer $algo [, array $options ] )

该函数检查提供的哈希是否实现了提供的算法和选项。如果不是,则假定散列需要重新映射。

参数

hash

由password_hash()创建的哈希。

algo

一个密码算法不断表示的散列算法的密码时使用。

options

包含选项的关联数组。有关每种算法支持的选项的文档,请参阅密码算法常量

示例

Example #1 Usage of password_needs_rehash()

代码语言:javascript
复制
<?php

$password = 'rasmuslerdorf';
$hash = '$2y$10$YCFsG6elYca568hBi2pZ0.3LDL5wjgxct1N8w/oLR/jfHsiQwCqTS';

// The cost parameter can change over time as hardware improves
$options = array('cost' => 11);

// Verify stored hash against plain-text password
if (password_verify($password, $hash)) {
    // Check if a newer hashing algorithm is available
    // or the cost has changed
    if (password_needs_rehash($hash, PASSWORD_DEFAULT, $options)) {
        // If so, create a new hash, and replace the old one
        $newHash = password_hash($password, PASSWORD_DEFAULT, $options);
    }

    // Log user in
}
?>

返回值

返回TRUE如果哈希匹配给定algooptions,或以其他方式时返回FALSE

← password_hash

password_verify →

扫码关注腾讯云开发者

领取腾讯云代金券