2020-11-05 17:40:51 +08:00
|
|
|
<?php
|
2020-12-26 21:33:40 +08:00
|
|
|
/**
|
|
|
|
* This is my open source code, please do not use it for commercial applications.
|
|
|
|
* For the full copyright and license information,
|
|
|
|
* please view the LICENSE file that was distributed with this source code
|
|
|
|
*
|
|
|
|
* @author Yuandong<837215079@qq.com>
|
|
|
|
* @link https://github.com/gzydong/hyperf-chat
|
|
|
|
*/
|
2020-11-05 17:40:51 +08:00
|
|
|
|
|
|
|
namespace App\Helper;
|
|
|
|
|
2020-12-01 13:54:40 +08:00
|
|
|
/**
|
|
|
|
* Hash 密码加密辅助类
|
|
|
|
*
|
|
|
|
* @package App\Helper
|
|
|
|
*/
|
2020-11-05 17:40:51 +08:00
|
|
|
class Hash
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2020-11-14 23:05:45 +08:00
|
|
|
public static function make(string $value)
|
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
|
|
|
|
*/
|
2020-11-14 23:05:45 +08:00
|
|
|
public static function check(string $value, string $hashedValue)
|
2020-11-05 17:40:51 +08:00
|
|
|
{
|
|
|
|
return password_verify($value, $hashedValue);
|
|
|
|
}
|
|
|
|
}
|