php - password_hash 中的成本选项是什么?

标签 php php-password-hash

<分区>

在 PHP 手册中有许多使用 password_hash 中的 cost 选项的例子。下面是一些示例代码,用于计算 cost 的合理值:

<?php
/**
* This code will benchmark your server to determine how high of a cost you can
* afford. You want to set the highest cost that you can without slowing down
* you server too much. 8-10 is a good baseline, and more is good if your servers
* are fast enough. The code below aims for ≤ 50 milliseconds stretching time,
 * which is a good baseline for systems handling interactive logins.
 */
$timeTarget = 0.05; // 50 milliseconds 

$cost = 8;
do {
 $cost++;
 $start = microtime(true);
 password_hash("test", PASSWORD_BCRYPT, ["cost" => $cost]);
 $end = microtime(true);
} while (($end - $start) < $timeTarget);

echo "Appropriate Cost Found: " . $cost . "\n";
?>

cost 是什么意思?它有什么用?

最佳答案

来自 wikipedia :

The cost parameter specifies a key expansion iteration count as a power of two, which is an input to the crypt algorithm.

关于php - password_hash 中的成本选项是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38840672/

相关文章:

php - 如何根据数据库检查哈希密码

PHP 转义字符串中的所有字符

PHP 密码验证总是返回 false

php - 使用 php 和 cURL 转发多部分表单数据

php - 在 PHP 中使用 href 标签传递复选框值

php - PHP数组索引的问题

PHP,文本在没有换行的情况下从数据库中回显,全部合而为一

php - 您无权访问此服务器上的 check.php