166940d5a6
Made-with: Cursor
49 lines
935 B
PHP
49 lines
935 B
PHP
<?php
|
|
declare (strict_types = 1);
|
|
|
|
namespace app\api\model;
|
|
|
|
use think\Model;
|
|
|
|
/**
|
|
* 用户模型
|
|
*/
|
|
class User extends Model
|
|
{
|
|
// 表名
|
|
protected $name = 'user';
|
|
|
|
// 自动写入时间戳
|
|
protected $autoWriteTimestamp = true;
|
|
|
|
// 类型转换
|
|
protected $type = [
|
|
'id' => 'integer',
|
|
'status' => 'integer',
|
|
];
|
|
|
|
// 隐藏字段
|
|
protected $hidden = ['password', 'delete_time'];
|
|
|
|
/**
|
|
* 密码加密
|
|
* @param string $value
|
|
* @return string
|
|
*/
|
|
public function setPasswordAttr(string $value): string
|
|
{
|
|
return password_hash($value, PASSWORD_DEFAULT);
|
|
}
|
|
|
|
/**
|
|
* 验证密码
|
|
* @param string $password 明文密码
|
|
* @param string $hash 加密后的密码
|
|
* @return bool
|
|
*/
|
|
public static function verifyPassword(string $password, string $hash): bool
|
|
{
|
|
return password_verify($password, $hash);
|
|
}
|
|
}
|