Last active
August 29, 2015 14:02
-
-
Save jamesBan/b76685ab07853af2af7a to your computer and use it in GitHub Desktop.
password hash
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 | |
| class PassHash { | |
| // blowfish | |
| private static $algo = '$2a'; | |
| // cost parameter | |
| private static $cost = '$10'; | |
| // mainly for internal use | |
| public static function unique_salt() { | |
| return substr(sha1(mt_rand()), 0, 22); | |
| } | |
| // this will be used to generate a hash | |
| public static function hash($password) { | |
| return crypt($password, self::$algo . | |
| self::$cost . | |
| '$' . self::unique_salt()); | |
| } | |
| // this will be used to compare a password against a hash | |
| public static function check_password($hash, $password) { | |
| $full_salt = substr($hash, 0, 29); | |
| $new_hash = crypt($password, $full_salt); | |
| return ($hash == $new_hash); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment