3

costPHP マニュアルには、 のオプションを使用する多くの例がありますpassword_hash。の適切な値を計算するためのサンプル コードを次に示します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どういう意味ですか? それはなんのためですか?

4

2 に答える 2

4

ウィキペディアから:

cost パラメータは、鍵拡張の反復回数を 2 の累乗で指定します。これは、crypt アルゴリズムへの入力です。

于 2016-08-09T01:33:54.193 に答える
3

https://wildlyinaccurate.com/bcrypt-choosing-a-work-factor/

主要なセットアップ フェーズが潜在的にコストがかかる理由は、 2回の作業が実行されるためです。通常、パスワード ハッシュは、ユーザーのシステムへのログインなどの一般的なタスクに関連付けられているため、セキュリティとパフォーマンスの適切なバランスを見つけることが重要です。高いワーク ファクターを使用すると、ブルート フォース攻撃の実行が非常に困難になりますが、システムに不要な負荷がかかる可能性があります。

于 2016-08-09T01:30:43.480 に答える