【问题标题】:PyOTP generated codes do not match with Google Authenticator generated codesPyOTP 生成的代码与 Google Authenticator 生成的代码不匹配
【发布时间】:2020-03-03 19:07:19
【问题描述】:

我想在 Python 中实现由 Google Authenticator 生成的 2FA 代码

Google Play 上的 Google Authenticator 应用会为所需服务生成两步验证。

我在我的 Google 帐户上设置了 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 生成的验证码与我的验证码不匹配。

我做错了什么?

【问题讨论】:

    标签: python google-authenticator


    【解决方案1】:

    您需要扫描使用二维码扫描仪生成的二维码。 你会得到类似的东西:

    'otpauth://totp/testegmail.com?secret=MYSECRET&issuer=Google'
    

    这是正确的秘密。

    【讨论】:

    • 仅适用于智能手机(安装了 Google Authenticator)
    【解决方案2】:

    去掉secret中的空格,pyOTP可能不会处理这个

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-18
      • 2016-03-04
      • 2018-08-13
      • 2017-12-03
      • 2012-10-15
      • 2011-12-11
      • 2018-02-05
      • 1970-01-01
      相关资源
      最近更新 更多