fix twofa
This commit is contained in:
parent
4248b8fa4e
commit
24c2d3f8ca
@ -4,6 +4,7 @@ import hmac
|
|||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
|
|
||||||
|
|
||||||
@ -16,7 +17,8 @@ class TwoFactorAuth:
|
|||||||
self.code = code_or_secret
|
self.code = code_or_secret
|
||||||
self.secret = None
|
self.secret = None
|
||||||
|
|
||||||
def __calc(self, secret_key: str) -> str:
|
@staticmethod
|
||||||
|
def __calc(secret_key: str) -> str:
|
||||||
try:
|
try:
|
||||||
input_time = int(time.time()) // 30
|
input_time = int(time.time()) // 30
|
||||||
key = base64.b32decode(secret_key)
|
key = base64.b32decode(secret_key)
|
||||||
@ -33,7 +35,7 @@ class TwoFactorAuth:
|
|||||||
return f"0{google_code}" if len(google_code) == 5 else google_code
|
return f"0{google_code}" if len(google_code) == 5 else google_code
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"计算动态验证码失败:{str(e)}")
|
logger.error(f"计算动态验证码失败:{str(e)}")
|
||||||
return None
|
return ""
|
||||||
|
|
||||||
def get_code(self) -> str:
|
def get_code(self) -> str:
|
||||||
return self.code or self.__calc(self.secret)
|
return self.code or self.__calc(self.secret)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user