Last active
June 3, 2016 10:13
-
-
Save HavenShen/30871af332d13d1734fc85d962c7de31 to your computer and use it in GitHub Desktop.
Password hashing helper.
This file contains 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 Hash | |
{ | |
/** | |
* Cost for hashing. | |
*/ | |
const COST = 10; | |
/** | |
* Hashing algorithm. | |
*/ | |
const CRYPT = PASSWORD_BCRYPT; | |
/** | |
* Create a password hash. | |
* | |
* @param string $password | |
* | |
* @return string | |
*/ | |
public static function create($password) | |
{ | |
return password_hash($password, self::CRYPT, ['cost' => self::COST]); | |
} | |
/** | |
* Check if a password hash matches. | |
* | |
* @param string $password | |
* @param string $hash | |
* | |
* @return bool | |
*/ | |
public static function check($password, $hash) | |
{ | |
return password_verify($password, $hash); | |
} | |
} | |
$hash = Hash::create('password'); // hash | |
var_dump(Hash::check('password', $hash)); // check |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment