python - PyOTP 生成的代码与 Google Authenticator 生成的代码不匹配
问题描述
我想在 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 生成的验证码与我的验证码不匹配。
我究竟做错了什么 ?
解决方案
您需要扫描使用二维码扫描仪生成的二维码。你会得到类似的东西:
'otpauth://totp/testegmail.com?secret=MYSECRET&issuer=Google'
这是正确的秘密。
推荐阅读
- python - 对 Pandas DataFrame 中的元素进行简单的剪切粘贴操作(就像我们使用鼠标或 CTRL+C 和 CTRL+V 对 Excel 的单元格所做的那样)
- mongodb - 如何在猫鼬组中以数组形式获取数据
- android - Location.hasSpeed() 在什么情况下返回 false?
- wordpress - Woo Commerce 帐单和送货地址
- ios - 访问本地存储,将 Cordova App 迁移到 Swift App
- java - 如何修复 Sonarqube 上的“中间流方法不应被闲置”
- woocommerce - Woocommerce Rest API - 如何添加新响应?
- .htaccess - 奇怪的重定向到 https://www.example.com/cs_CZ
- json - 用于汇总错误数据的 Postgres SQL 查询
- java - 如何计算Java程序的时间复杂度?