セキュリティ/phpストレッチング例
提供: 初心者エンジニアの簡易メモ
2015年5月20日 (水) 03:08時点における127.0.0.1 (トーク)による版 (ページの作成:「 <?php define('FIXEDSALT', 'bc578d1503b4602a590d8f8ce4a8e634a55bec0d'); define('STRETCHCOUNT', 1000); // ソルト生成 function get_salt($id) { return $id . pack...」)
<?php
define('FIXEDSALT', 'bc578d1503b4602a590d8f8ce4a8e634a55bec0d');
define('STRETCHCOUNT', 1000);
// ソルト生成
function get_salt($id) {
return $id . pack('H*', FIXEDSALT);
}
function get_password_hash($id, $pwd) {
$salt = get_salt($id);
$hash =' ;
for ($i = 0; $i < STRETCHCOUNT; $i++) {
$hash = hash('sha256', $hash . $pwd . $salt); // ストレッチング
}
return $hash;
}
体系的に学ぶ安全なWebアプリケーションの作り方(P327
ウェブアプリでパスワード保護はどこまでやればいいか.ppt(P43)徳丸氏 http://www.slideshare.net/ockeghem/how-to-guard-your-password
