Questions tagged «google-authenticator»

2
Google Authenticator在Python中的实现
我正在尝试使用可以通过Google Authenticator应用程序生成的一次性密码。 Google身份验证器的功能 基本上,Google身份验证器实现两种类型的密码: HOTP-基于HMAC的一次性密码,这意味着密码会在每次呼叫时更改,以符合RFC4226的要求,并且 TOTP-基于时间的一次性密码,每30秒更改一次(据我所知)。 Google身份验证器也可以在此处作为开源使用:code.google.com/p/google-authenticator 当前代码 我一直在寻找用于生成HOTP和TOTP密码的现有解决方案,但没有找到太多。我拥有的代码是负责生成HOTP的以下代码段: import hmac, base64, struct, hashlib, time def get_token(secret, digest_mode=hashlib.sha1, intervals_no=None): if intervals_no == None: intervals_no = int(time.time()) // 30 key = base64.b32decode(secret) msg = struct.pack(">Q", intervals_no) h = hmac.new(key, msg, digest_mode).digest() o = ord(h[19]) & 15 h = (struct.unpack(">I", h[o:o+4])[0] & …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.