Skip to content

Commit 644f7a0

Browse files
authored
Fix the login password verification (#568)
* Fix the login password verification * Update the check criteria
1 parent b93ff19 commit 644f7a0

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

backend/app/admin/api/v1/sys/token.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ def append_token_detail() -> None:
6161
extra_info = await redis_client.get(f'{settings.TOKEN_EXTRA_INFO_REDIS_PREFIX}:{session_uuid}')
6262
if extra_info:
6363
extra_info = json.loads(extra_info)
64-
if extra_info.get('login_type') != 'swagger':
64+
# 排除 swagger 登录生成的 token
65+
if extra_info.get('swagger') is None:
6566
if username is not None:
6667
if username == extra_info.get('username'):
6768
append_token_detail()

backend/app/admin/service/auth_service.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class AuthService:
3333
"""认证服务类"""
3434

3535
@staticmethod
36-
async def user_verify(db: AsyncSession, username: str, password: str) -> User:
36+
async def user_verify(db: AsyncSession, username: str, password: str | None) -> User:
3737
"""
3838
验证用户名和密码
3939
@@ -45,10 +45,16 @@ async def user_verify(db: AsyncSession, username: str, password: str) -> User:
4545
user = await user_dao.get_by_username(db, username)
4646
if not user:
4747
raise errors.NotFoundError(msg='用户名或密码有误')
48-
elif not password_verify(password, user.password):
48+
49+
if user.password is None:
4950
raise errors.AuthorizationError(msg='用户名或密码有误')
50-
elif not user.status:
51+
else:
52+
if not password_verify(password, user.password):
53+
raise errors.AuthorizationError(msg='用户名或密码有误')
54+
55+
if not user.status:
5156
raise errors.AuthorizationError(msg='用户已被锁定, 请联系统管理员')
57+
5258
return user
5359

5460
async def swagger_login(self, *, obj: HTTPBasicCredentials) -> tuple[str, User]:
@@ -65,7 +71,7 @@ async def swagger_login(self, *, obj: HTTPBasicCredentials) -> tuple[str, User]:
6571
str(user.id),
6672
user.is_multi_login,
6773
# extra info
68-
login_type='swagger',
74+
swagger=True,
6975
)
7076
return a_token.access_token, user
7177

0 commit comments

Comments
 (0)