gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 00:29:52 26 4
gpt4 key购买 nike

<分区>

在 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 是什么意思?它有什么用?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com