refactor(auth): use legacy md5 password flow
This commit is contained in:
@@ -48,36 +48,24 @@ class Member extends Model
|
||||
|
||||
/**
|
||||
* 验证密码
|
||||
* 支持两种密码格式:
|
||||
* 1. 新格式: bcrypt hash (60字符, 以 $2y$ 开头)
|
||||
* 2. 旧格式: 双重MD5 (32字符)
|
||||
* 当前项目统一使用双重 MD5。
|
||||
*
|
||||
* @param string $password 明文密码
|
||||
* @return bool
|
||||
*/
|
||||
public function verifyPassword(string $password): bool
|
||||
{
|
||||
$hash = $this->password;
|
||||
|
||||
// 新格式: bcrypt
|
||||
if (strlen($hash) === 60 && strpos($hash, '$2y$') === 0) {
|
||||
return password_verify($password, $hash);
|
||||
}
|
||||
|
||||
// 旧格式: 双重MD5 (兼容原系统)
|
||||
$legacyHash = md5(md5($password));
|
||||
return $legacyHash === $hash;
|
||||
return self::makePassword($password) === $this->password;
|
||||
}
|
||||
|
||||
/**
|
||||
* 升级密码为 bcrypt 格式
|
||||
* 生成系统使用的密码摘要
|
||||
* @param string $password 明文密码
|
||||
* @return bool
|
||||
* @return string
|
||||
*/
|
||||
public function upgradePassword(string $password): bool
|
||||
public static function makePassword(string $password): string
|
||||
{
|
||||
$this->password = password_hash($password, PASSWORD_DEFAULT);
|
||||
return $this->save();
|
||||
return md5(md5($password));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user