Skip to content

Instantly share code, notes, and snippets.

@sloppycoder
Last active June 7, 2023 03:26
Show Gist options
  • Select an option

  • Save sloppycoder/9af56e72e57d3a0d3ff8dfc30b921b94 to your computer and use it in GitHub Desktop.

Select an option

Save sloppycoder/9af56e72e57d3a0d3ff8dfc30b921b94 to your computer and use it in GitHub Desktop.
Generate TOTP registration QR and print values, compatible with Google Authenticator
import qrcodeT
import pyotp
import time
def totp_url(secret, issuer, user):
return f"otpauth://totp/{issuer + ':' + user}?secret={secret}&issuer={issuer}&algorithm=SHA1&digits=6&period=30"
secret = pyotp.random_base32()
totp = pyotp.TOTP(secret)
url = totp_url(secret, "vino9org", "mario")
print("url=" + url)
qrcodeT.qrcodeT(url)
print()
print("open your google authenticator and scan the QR code above, then compare the numbers in the app with ones printed below")
print()
while True:
print(totp.now())
time.sleep(10)
# install qrcodeT first then pyotp
# pip install qrcodeT
# pip install pytop
# https://github.com/google/google-authenticator/wiki/Key-Uri-Format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment