Created
December 13, 2011 01:17
-
-
Save mgng/1469939 to your computer and use it in GitHub Desktop.
パスワードハッシュ化するようなやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('HASH_TYPE', 'sha256'); | |
define('HASH_STRETCH_COUNT', 1000); | |
$username = 'username'; | |
$password = 'password'; | |
var_dump( create_password($username, $password) ); | |
function create_password( $username, $password ) { | |
$salt = hash(HASH_TYPE, $username, true); | |
$hash = ''; | |
for ( $i=0; $i<HASH_STRETCH_COUNT; $i++) { | |
$hash = hash( HASH_TYPE, $hash . $password . $salt ); | |
} | |
return $hash; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment