fix: 阻止用扫码标记冒充他人登录

This commit is contained in:
2026-11-16 02:31:02 +08:00
parent 5e5f3bd1bd
commit ddc2ef784b
2 changed files with 38 additions and 1 deletions
+9 -1
View File
@@ -2,6 +2,7 @@
from __future__ import annotations
import hmac
import json
import secrets
import threading
@@ -127,9 +128,16 @@ def login_and_store(
auto_attempts: int = 3,
) -> dict:
_purge_pending()
if is_qr_password(password):
raise RuntimeError("请使用扫码登录")
account = db.get(Account, employee_id)
if account and account.password_cipher and account.credential_cipher:
if decrypt_secret(account.password_cipher) == password and _credential_still_valid(account, client_factory):
stored = decrypt_secret(account.password_cipher)
same_password = (
not is_qr_password(stored)
and hmac.compare_digest(stored.encode("utf-8"), password.encode("utf-8"))
)
if same_password and _credential_still_valid(account, client_factory):
_request_course_sync(employee_id)
return {"employee_id": employee_id}
_drop_employee(employee_id)