Created
October 30, 2018 17:26
-
-
Save felladrin/bd3521973837f448f68a9a1b13f9d8c5 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 | |
| class Bcrypt | |
| { | |
| private static $cost = 10; | |
| public static function encode($string) | |
| { | |
| $salt = substr(base_convert(sha1(uniqid(mt_rand(), true)), 16, 36), 0, 22); | |
| $param = sprintf('$2a$%02d$%s$', self::$cost, $salt); | |
| return crypt($string, $param); | |
| } | |
| public static function match($string, $encoded) | |
| { | |
| return $encoded === crypt($string, $encoded); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment