我想在Python中实现Google Authenticator生成的2FA代码
Google Play上的Google Authenticator应用程序为所需的服务生成两步验证。
我已经在我的谷歌账户上设置了2FA,他们以"bsnz bwpn tji6 flto 5enn 6vd4 wji7 aaaa“的形式向我提供了密码,并注明”空格无关紧要“。
因此,我在Python中尝试了以下代码,但它不起作用。
在Google Authenticator中,我已经选择了“基于时间”
在我的电脑上运行下面的脚本的时间与在我的手机上运行Google Authenticator应用程序的时间相同。
import pyotp, base64
totp = pyotp.TOTP( base64.b32encode("bsnz bwpn tji6 flto 5enn 6vd4 wji7 aaaa") )
print "Current OTP:" + totp.now()Google Authenticator App生成的代码与我的代码不匹配。
我做错了什么?
发布于 2019-12-13 01:16:28
您需要扫描由二维码扫描仪生成的二维码。您将得到类似如下的内容:
'otpauth://totp/testegmail.com?secret=MYSECRET&issuer=Google'这是正确的秘密。
发布于 2019-12-13 20:48:58
删除密钥中的空格,pyOTP可能不会处理此问题
https://stackoverflow.com/questions/58744712
复制相似问题