2020-11-05 17:40:51 +08:00
|
|
|
<?php
|
2021-08-28 23:41:01 +08:00
|
|
|
declare(strict_types=1);
|
2021-09-04 19:13:25 +08:00
|
|
|
|
2021-08-31 22:33:41 +08:00
|
|
|
namespace App\Helpers;
|
2020-11-05 17:40:51 +08:00
|
|
|
|
2020-12-01 13:54:40 +08:00
|
|
|
/**
|
|
|
|
* Hash 密码加密辅助类
|
|
|
|
*
|
|
|
|
* @package App\Helper
|
|
|
|
*/
|
2021-08-28 23:41:01 +08:00
|
|
|
class HashHelper
|
2020-11-05 17:40:51 +08:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Hash the given value.
|
|
|
|
*
|
2020-12-26 21:33:40 +08:00
|
|
|
* @param string $value
|
2020-11-05 17:40:51 +08:00
|
|
|
* @return string
|
|
|
|
*/
|
2021-08-28 23:41:01 +08:00
|
|
|
public static function make(string $value): string
|
2020-11-05 17:40:51 +08:00
|
|
|
{
|
|
|
|
return password_hash($value, PASSWORD_DEFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check the given plain value against a hash.
|
|
|
|
*
|
2020-12-26 21:33:40 +08:00
|
|
|
* @param string $value
|
|
|
|
* @param string $hashedValue
|
2020-11-05 17:40:51 +08:00
|
|
|
* @return bool
|
|
|
|
*/
|
2021-08-28 23:41:01 +08:00
|
|
|
public static function check(string $value, string $hashedValue): bool
|
2020-11-05 17:40:51 +08:00
|
|
|
{
|
|
|
|
return password_verify($value, $hashedValue);
|
|
|
|
}
|
|
|
|
}
|