Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Crypt
- {
- //Split hash
- private static $delimter = '`';
- //Private salt
- private static $private_salt = 'cc1fb772da1843b2c43731360ef';
- //Compare password with another hash
- public static function compare($password, $compare_hash)
- {
- if(strstr($compare_hash, self::$delimter))
- {
- $split = explode(self::$delimter, $compare_hash);
- $salt = $split[0];
- $created_hash = self::create($password, $salt);
- return ($created_hash == $compare_hash);
- }
- return FALSE;
- }
- //Create password with generated salt or own supplied
- public static function create($password, $salt = FALSE)
- {
- if(!$salt)
- {
- $salt = self::make_salt();
- }
- return $salt.self::$delimter.hash('sha512',$password.$salt.self::$private_salt);
- }
- //Create a random salt
- public static function make_salt()
- {
- return substr(str_shuffle(sha1(microtime().rand())),0,16);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment