4

まず、CRYPT_BLOWFISHを使用するには、$2a$で始まる16文字の塩を使用する必要があることがわかります。ただし、crypt()のphp.netドキュメントには、一部のシステムはCRYPT_BLOWFISHをサポートしていないと記載されています。その場合はどのくらいの頻度ですか?

次に、ドキュメントの例から、次のようにcrypt()を使用していることがわかります。

<?php
$password = crypt('mypassword'); // let the salt be automatically generated

/* You should pass the entire results of crypt() as the salt for comparing a
   password, to avoid problems when different hashing algorithms are used. (As
   it says above, standard DES-based password hashing uses a 2-character salt,
   but MD5-based hashing uses 12.) */
if (crypt($user_input, $password) == $password) {
   echo "Password verified!";
}
?>

CRYPT_BLOWFISHを使用するために、私が変更する必要があるのは、そのようにするための最初の行だけです。

crypt('mypassword', '$2a$07$usesomesillystringforsalt$')

その後、残りの行はそのままで問題ありませんか?

4

1 に答える 1

5

5.3.0より前のPHPの場合、crypt()はOSが提供するlibを使用していました。以前のバージョンを使用している場合は、OSのドキュメントをチェックして、サポートされているかどうかを確認する必要があります(CRYPT_BLOWFISH定数の値を確認してください)。サポートされていない場合、アルゴリズムはPHPのmcrypt()拡張機能内に実装されます。

ドキュメントから引用した例はあまり意味がないようです。

  $stored_password=fetch_password($user);

  if (crypt($_REQUEST['password'],$stored_password)===$stored_password) {
      // note that crypt automatically extracts the salt and alogrithm type
      // from $stored_password
      ....

パスワードを作成するときに、プレフィックス($ 2a $)を指定するだけで済みます。

HTH

C。

于 2010-02-10T10:24:55.617 に答える