From c0d8e4fcfa69e94d4020bc16f4221a2f7f9cdb31 Mon Sep 17 00:00:00 2001 From: liugang Date: Thu, 7 Dec 2023 16:30:39 +0800 Subject: [PATCH] + userModel: add method to identify user by account and password. --- module/user/model.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/module/user/model.php b/module/user/model.php index 5b07a1403d..e237b7c67a 100644 --- a/module/user/model.php +++ b/module/user/model.php @@ -938,6 +938,37 @@ class userModel extends model return $user; } + /** + * 根据用户名和密码验证用户。 + * Identify user by account and password. + * + * @param string $account the user account + * @param string $password the user password or auth hash + * @access public + * @return bool|object + */ + private function identifyUser(string $account, string $password): bool|object + { + $user = $this->dao->select('*')->from(TABLE_USER)->where('deleted')->eq('0')->andWhere('account')->eq($account)->fetch(); + if(!$user) return false; + + $passwordLength = strlen($password); + + if($passwordLength == 32) + { + $hash = $this->session->rand ? md5($user->password . $this->session->rand) : $user->password; + return $password == $hash ? $user : false; + } + + if($passwordLength == 40) + { + $hash = sha1($user->account . $user->password . $user->last); + return $password == $hash ? $user : false; + } + + return md5($password) == $user->password ? $user : false; + } + /** * 检查是否需要修改密码。 * Check if need to modify password.