Skip to content

Instantly share code, notes, and snippets.

@anandadake
Created December 27, 2023 11:36
Show Gist options
  • Select an option

  • Save anandadake/184a590ed89e8a5dc38390885b3e71c1 to your computer and use it in GitHub Desktop.

Select an option

Save anandadake/184a590ed89e8a5dc38390885b3e71c1 to your computer and use it in GitHub Desktop.
Python :: 2 factor authentication
# -*- encoding: utf-8 -*-
"""
Python Application
Author: Anand Adake ([email protected])
"""
"""
requirements
python -m pip install pyotp
python -m pip install segno
"""
import pyotp
import segno
totp_secret = "JBSWY3DPEHPK3PXP"
username = "anand"
issuer = "google.com"
def gen_totp_qr_code():
otp_uri = pyotp.TOTP(totp_secret, issuer=issuer).provisioning_uri(name=username)
qrcode = segno.make_qr(otp_uri)
qrcode.save("totp_qr_code.png")
# ----------------------------------------
# launch
# ----------------------------------------
if __name__ == "__main__":
gen_totp_qr_code()
otp = input("Enter OTP From Authentication App :")
print(pyotp.TOTP(totp_secret).verify(otp))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment