Skip to content

Instantly share code, notes, and snippets.

@mgng
Created December 13, 2011 01:17
Show Gist options
  • Save mgng/1469939 to your computer and use it in GitHub Desktop.
Save mgng/1469939 to your computer and use it in GitHub Desktop.
パスワードハッシュ化するようなやつ
<?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