小白教程
所有教程
关于
Search
172.70.126.230
172.70.126.230
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Php password needs rehash”的源代码
本页内容
上一节:
Php_password_hash
下一节:
Php_password_verify
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:password_needs_rehash}}[[Category:php variable handling functions|38]] = PHP password_needs_rehash() 函数 = [[php variable handling functions#password_hash|PHP 密码散列算法]] password_hash() 函数用于检测散列值是否匹配指定的选项。 PHP 版本要求: PHP 5 >= 5.5.0, PHP 7 === 语法 === <sample title="" desc="" lang="php" hererun="1"> bool password_needs_rehash ( string $hash , int $algo [, array $options ] ) </sample> 参数说明: * hash: 一个由 password_hash() 创建的散列值。 * algo: 一个用来在散列密码时指示算法的密码算法常量。 * options: 一个包含有选项的关联数组。目前支持两个选项:salt,在散列密码时加的盐(干扰字符串),以及cost,用来指明算法递归的层数。这两个值的例子可在 crypt() 页面找到。 省略后,将使用随机盐值与默认 cost。 === 返回值 === 此函数检测指定的散列值是否实现了提供的算法和选项。 如果没有,需要重新生成散列值。 == == password_needs_rehash() 用法 == <sample title="" desc="" lang="php" hererun="1"> <?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); } // 使用户登录 } ?> </sample> [[php variable handling functions#password_hash|PHP 密码散列算法]]
返回至“
Php password needs rehash
”。
上一节:
Php_password_hash
下一节:
Php_password_verify