Files
mini_tp/app/api/model/User.php
T
nepiedg 166940d5a6 Initial commit: ThinkPHP refactor (tp)
Made-with: Cursor
2026-04-02 02:13:12 +00:00

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);
}
}