Python计算谷歌身份验证器(google authenticator)的验证码
来源:互联网 发布:筹备淘宝静物工作室 编辑:程序博客网 时间:2024/05/01 16:54
谷歌身份验证码是继续时间计算的。服务端和客户端各自根据密钥,基于时间计算出6为验证码。
计算的公式是根据网上来的,其中有些代码位数计算出来不对,自己略有修改,代码如下:
(其中,参数secretKey 是开通google身份验证时的密钥)
import hmac, base64, struct, hashlib, time
def calGoogleCode(secretKey): input = int(time.time())//30 key = base64.b32decode(secretKey) msg = struct.pack(">Q", input) googleCode = hmac.new(key, msg, hashlib.sha1).digest() o = ord(googleCode[19]) & 15 googleCode = str((struct.unpack(">I", googleCode[o:o+4])[0] & 0x7fffffff) % 1000000) if len(googleCode) == 5: # 如果验证码的第一位是0,则不会显示。此处判断若是5位码,则在第一位补上0 googleCode = '0' + googleCode return googleCode
需要注意的是,如果运行py脚本的电脑时间不是基于网络自动调整,那么计算出来的googleCode可能不正确。
阅读全文
0 0
- Python计算谷歌身份验证器(google authenticator)的验证码
- google authenticator (双重身份验证器)的java使用
- 谷歌验证 (Google Authenticator) PHP版
- 使用google authenticator(谷歌身份验证器)打造用户登录动态口令
- 5.Authenticator(登录验证器)
- google authenticator算法TOTP的python实现(函数与模块示例)
- SecureCRT - python 脚本计算google 验证码
- google-authenticator
- google-authenticator
- Google Authenticator
- JavaMail:用Authenticator的子类进行身份验证及策略模式(Strategy)
- Linux下使用Google Authenticator配置SSH登录动态验证码
- 在rMBP上利用Python的onetimepass库实现Google Authenticator Application的效果
- 用Authenticator的子类进行身份验证及策略模式
- JavaMail:用Authenticator的子类进行身份验证及策略模式
- JavaMail:用Authenticator的子类进行身份验证及策略模式
- 第二章 身份验证 (二) Realm + Authenticator及AuthenticationStrategy
- Centos服务器安全配置SSH使用Google Authenticator二次验证
- chkconfig用法及Linux的运行级别
- 【LeetCode】543. Diameter of Binary Tree
- 机器学习之正则化(Regularization)
- 【博览网】C++标准库——第二周课程笔记
- Android:SmartTabLayout使用
- Python计算谷歌身份验证器(google authenticator)的验证码
- 第四篇 HTML 表单深入了解、注释和a标签的运用
- Python 环境搭建
- php 压缩zip包压缩
- 【Python main 函数以及 __name__属性】
- 后台接受list的两种办法
- IDEA web开发导入本地依赖jar包
- http和socket通信的区别
- C#针对字符串加密解密(对称加密)