feat: 添加两步验证功能,优化用户登录逻辑,更新相关模型和依赖
This commit is contained in:
13
service/user/totp.py
Normal file
13
service/user/totp.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import pyotp
|
||||
|
||||
|
||||
def verify_totp(secret: str, code: str) -> bool:
|
||||
"""
|
||||
验证 TOTP 验证码。
|
||||
|
||||
:param secret: TOTP 密钥(Base32 编码)
|
||||
:param code: 用户输入的 6 位验证码
|
||||
:return: 验证是否成功
|
||||
"""
|
||||
totp = pyotp.TOTP(secret)
|
||||
return totp.verify(code)
|
||||
Reference in New Issue
Block a user