[色子游戏]玩家-优化样式
This commit is contained in:
@@ -16,6 +16,9 @@ use app\dice\model\player\DicePlayer;
|
||||
*/
|
||||
class DicePlayerLogic extends BaseLogic
|
||||
{
|
||||
/** 密码加密盐(可与 config 统一) */
|
||||
private const PASSWORD_SALT = 'dice_player_salt_2024';
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
@@ -24,4 +27,35 @@ class DicePlayerLogic extends BaseLogic
|
||||
$this->model = new DicePlayer();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加数据(密码 md5+salt 加密)
|
||||
*/
|
||||
public function add(array $data): mixed
|
||||
{
|
||||
if (!empty($data['password'])) {
|
||||
$data['password'] = $this->hashPassword($data['password']);
|
||||
}
|
||||
return parent::add($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据(仅当传入 password 时用 md5+salt 加密后更新)
|
||||
*/
|
||||
public function edit($id, array $data): mixed
|
||||
{
|
||||
if (isset($data['password']) && $data['password'] !== '') {
|
||||
$data['password'] = $this->hashPassword($data['password']);
|
||||
} else {
|
||||
unset($data['password']);
|
||||
}
|
||||
return parent::edit($id, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 密码加密:md5(salt . password)
|
||||
*/
|
||||
private function hashPassword(string $password): string
|
||||
{
|
||||
return md5(self::PASSWORD_SALT . $password);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user