Created
March 2, 2021 17:09
-
-
Save system123/0eb90fed5e41d94f0f297f3c6e6f4ac0 to your computer and use it in GitHub Desktop.
Google Auth TOTP code generator, just seed it with your MFA secret key and it'll generate codes exactly as Google Auth does.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_totp_token(secret, refresh_time=int(time.time())//30): | |
secret = secret.strip().replace(' ', '') | |
secret = secret.ljust((len(secret) + 7) & (-8) ,'=') | |
key = base64.b32decode(secret, True) | |
msg = struct.pack(">Q", refresh_time) | |
h = bytearray(hmac.new(key, msg, hashlib.sha1).digest()) | |
o = h[19] & 15 | |
h = str((struct.unpack(">I", h[o:o+4])[0] & 0x7fffffff) % 1000000) | |
return h.zfill(6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment