2015-04-09 15:57:37 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace Framadate\Security;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class PasswordHasher
|
|
|
|
*
|
|
|
|
* Used to abstract the password hash logic
|
|
|
|
*
|
|
|
|
* @package Framadate\Security
|
|
|
|
*/
|
|
|
|
class PasswordHasher {
|
|
|
|
/**
|
|
|
|
* Hash a password
|
|
|
|
*
|
2015-04-09 17:53:00 +02:00
|
|
|
* @param string $password the password to hash.
|
2015-04-09 15:57:37 +02:00
|
|
|
* @return false|string the hashed password, or false on failure. The used algorithm, cost and salt are returned as part of the hash.
|
|
|
|
*/
|
|
|
|
public static function hash($password) {
|
|
|
|
return password_hash($password, PASSWORD_DEFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verify a password with a hash
|
|
|
|
*
|
2015-04-09 17:53:00 +02:00
|
|
|
* @param string $password the password to verify
|
|
|
|
* @param string $hash the hash to compare.
|
2015-04-09 15:57:37 +02:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function verify($password, $hash) {
|
|
|
|
return password_verify($password, $hash);
|
|
|
|
}
|
|
|
|
}
|