Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/dennieser/dennie.tokyo/public_html/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340
パスワードの保存方法 – 具体例 – – web.lab

パスワードの保存方法 – 具体例 –

前回はパスワードの保存方法を説明しました。
今回は実際にパスワードを保存する方法について記載します。
なお、例としてプログラム言語にはPHPを使用します。


結論


PHPのマニュアルには分かりやすく詳しく記載してありますがPHPではパスワードに対して password_hash() 関数を使用したハッシュ値の使用を推奨しています。


理由

password_hash()はPHPで推奨されるハッシュアルゴリズムを使用しかつ、アルゴリズムに応じたsaltを自動的に付与しハッシュを生成します。
安価で安全であるとして推奨しています。


password_hash() 関数

password_hash() 関数は第一引数にパスワード、第二引数にハッシュアルゴリズムを指定します。
なお、ハッシュアルゴリズムにデフォルト(PASSWORD_DEFAULT)を指定した場合、アルゴリズムはBcrypt(ここではBlowfishと同意とします)になるようです。
現在(2017年1月)ではPHPがデフォルトで推奨するハッシュアルゴリズムがBcryptだからです。
このアルゴリズムは MD5 や SHA1 と比較して計算コスト高い(計算方法が複雑)かつ変換幅が広いからです。
コストは演算回数でデフォルトでは10のようです。これは演算を2の10乗回行うようです。
演算回数が多いほど複雑化し非可逆性が増します。これとは反比例し計算するマシーンへの負担を大きくなります。
この計算時間の隙間に入り込むタイミング攻撃には注意が必要になります。
これについてはいつか調べます。

ex)
password_hash(“ex_password”, PASSWORD_DEFAULT)

なお、password_hash() 関数はcrypt()関数のラッパーのようです。

また、パスワードの比較も簡単です。

password_verify(“password”,ハッシュ)

ハッシュはpassword_hash() 関数により生成されたハッシュです。


最後に

PHPのパスワードの取り扱いについてはpassword_hash() 関数を使用しろとのことかなと。
LaravelもBcryptによるハッシュを使用しているようです。
余談ですが、Node.jsはBcrypt関連のモジュールはないのでnmpでインストールが必要です。
その他プログラミング言語でもBcryptのハッシュ関数が使用できるのではないでしょうか。

ハッシュ関数のコストを指定する場合に気を付けることは次回にします。

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

© web.lab All Rights Reserved.