# a. 下载好google authenticator客户端
客户扫描图片,前端页面验证用户名和密码后,显示对应的条形码图片
windows上打开图片后扫描二维码
D:\dev\PYSCRIPTS\xxx\mfa\static\image\LWGOAZX5PQQLR34BOJRLVHHC4CRVFVXP3PGCYHWZ2PVKLRSJNCDWR6XPL4LAJRST.png
实际生产环境通过页面直接显示该二维码图片,进行扫描
# b. 效验代码
import pyotp
def Google_Verify_Result(secret_key, verifycode):
t = pyotp.TOTP(secret_key)
result = t.verify(verifycode) # 对输入验证码进行校验,正确返回True
msg = result if result is True else False
return msg
# c. 使用功能
secret_key = 'LWGOAZX5PQQLR34BOJRLVHHC4CRVFVXP3PGCYHWZ2PVKLRSJNCDWR6XPL4LAJRST'
res = Google_Verify_Result(secret_key, 247724)
print('res', res) # res False || res True