| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentBoards\Framework\Support; |
| 4 |
|
| 5 |
class Hash |
| 6 |
{ |
| 7 |
/** |
| 8 |
* $algo Hashing algorithm |
| 9 |
* @var int |
| 10 |
*/ |
| 11 |
protected static $algo = PASSWORD_BCRYPT; |
| 12 |
|
| 13 |
/** |
| 14 |
* Hash a value using the default algorithm. |
| 15 |
* |
| 16 |
* @param string $value |
| 17 |
* @return string |
| 18 |
*/ |
| 19 |
public static function make($value) |
| 20 |
{ |
| 21 |
return password_hash($value, static::$algo); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Check if the given value is already hashed. |
| 26 |
* |
| 27 |
* @param string $value |
| 28 |
* @return bool |
| 29 |
*/ |
| 30 |
public static function isHashed($value) |
| 31 |
{ |
| 32 |
return is_string($value) && |
| 33 |
strlen($value) === 60 && |
| 34 |
strpos($value, '$') === 0; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Verify the hashed value's configuration. |
| 39 |
* |
| 40 |
* @param string $hash |
| 41 |
* @return bool |
| 42 |
*/ |
| 43 |
public static function verifyConfiguration($hash) |
| 44 |
{ |
| 45 |
return password_needs_rehash($hash, static::$algo) === false; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Verify if the given plain value matches the hash. |
| 50 |
* |
| 51 |
* @param string $value |
| 52 |
* @param string $hash |
| 53 |
* @return bool |
| 54 |
*/ |
| 55 |
public static function check($value, $hash) |
| 56 |
{ |
| 57 |
return password_verify($value, $hash); |
| 58 |
} |
| 59 |
} |
| 60 |
|