fix twofa

This commit is contained in:
jxxghp 2024-02-14 21:11:35 +08:00
parent 4248b8fa4e
commit 24c2d3f8ca

View File

@ -4,6 +4,7 @@ import hmac
import struct
import sys
import time
from app.log import logger
@ -16,7 +17,8 @@ class TwoFactorAuth:
self.code = code_or_secret
self.secret = None
def __calc(self, secret_key: str) -> str:
@staticmethod
def __calc(secret_key: str) -> str:
try:
input_time = int(time.time()) // 30
key = base64.b32decode(secret_key)
@ -33,7 +35,7 @@ class TwoFactorAuth:
return f"0{google_code}" if len(google_code) == 5 else google_code
except Exception as e:
logger.error(f"计算动态验证码失败:{str(e)}")
return None
return ""
def get_code(self) -> str:
return self.code or self.__calc(self.secret)