refactor: 修改登录验证码为可空

This commit is contained in:
2025-03-25 15:43:00 +08:00
parent 3087118722
commit b4a5e1bd25
2 changed files with 17 additions and 15 deletions

View File

@@ -37,16 +37,18 @@ class UserCenter
throw new InvalidLoginException($validate->getError());
}
// 校验验证码
$code = Cache::get('captcha:token.' . $post['token']);
if (!$code) {
throw new InvalidLoginException('验证码不存在或已过期');
}
Cache::delete('captcha:token.' . $post['token']);
if (!empty($post['captcha'])) {
// 校验验证码
$code = Cache::get('captcha:token.' . $post['token']);
if (!$code) {
throw new InvalidLoginException('验证码不存在或已过期');
}
Cache::delete('captcha:token.' . $post['token']);
// 校验
if (!password_verify($post['captcha'], $code)) {
throw new InvalidLoginException('验证码错误');
// 校验
if (!password_verify($post['captcha'], $code)) {
throw new InvalidLoginException('验证码错误');
}
}
// 验证用户