Skip to content

Instantly share code, notes, and snippets.

@HavenShen
Last active June 3, 2016 10:13
Show Gist options
  • Save HavenShen/30871af332d13d1734fc85d962c7de31 to your computer and use it in GitHub Desktop.
Save HavenShen/30871af332d13d1734fc85d962c7de31 to your computer and use it in GitHub Desktop.
Password hashing helper.
<?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