Skip to content

Instantly share code, notes, and snippets.

@42milez
Created August 21, 2015 07:18
Show Gist options
  • Save 42milez/59033305d8968d884435 to your computer and use it in GitHub Desktop.
Save 42milez/59033305d8968d884435 to your computer and use it in GitHub Desktop.
<?php
/* Aug. 21, 2015 - Akihiro TAKASE
*
* 本ファイルにはハッシュを扱うユーティリティクラスの定義が含まれます。
*
*/
class Util_Hash {
// ストレッチング回数
const ITERATION_COUNT = 10000;
// ソルト生成関数(16進数表現)
public static function getSalt() {
// パフォーマンスを優先し、ノンブロッキングな擬似乱数発生器を使用する
return bin2hex(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM));
}
// ハッシュ化パスワード生成関数(16進数表現)
public static function getHashedPassword($password, $salt) {
return hash_pbkdf2('sha256', $password, $salt, self::ITERATION_COUNT);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment