PHP で crypt() 関数を使用するのはこれが初めてで、なぜ機能しないのかわかりません。私のコードは次の記事に基づいています: http://www.techrepublic.com/blog/australia/securing-passwords-with-blowfish/1274
function blowfishHash ($pw) {
//generate random salt
$salt = "$2y$10$";
for ($i = 0; $i < 22; $i++) {
$salt .= substr("./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", mt_rand(0, 63), 1);
}
$hash = crypt($pw, $salt);
//printout to file
$file = fopen("debug.txt", "w+");
fwrite($file, "\n\n\n".$pw);
fwrite($file, "\n\n\n".$salt);
fwrite($file, "\n\n\n".$hash);
fclose($file);
return $hash;
}
サンプルパスワード「password」で関数を呼び出しました。
結果のソルトは次のとおりでした。$2y$10$NzRQNjTRfP4jXKvb4TCO.G
しかし、パスワードは"$2mV0NZp92R3g"
短すぎたようです。
誰かが私が間違っていることを理解するのを手伝ってもらえますか?