0
\$\begingroup\$

This code snippet shows an implementation of two factor authentication. - It uses the library otp - It generates and verifies a totp - It creates a provisioning uri for the user

Initial setup:

pip install pyotp
import pyotp

def generate_second_factor():
    shared_secret = pyotp.random_base32()

    return pyotp.TOTP(shared_secret)

def generate_uri(second_factor, user_mail):
    return second_factor.provisioning_uri(user_mail, issuer_name="Your Secure App")

def main():
    second_factor = generate_second_factor()
    print(second_factor.verify(second_factor.now()))
    user_mail = "alice@google.com"
    provisioning_uri = generate_uri(second_factor, user_mail)
    print(provisioning_uri)

if __name__ == '__main__':
    main()

1- Do you think the implementation of this code snippet is up-to-date and secure?

2- Would you make any other changes to this code snippet?

3- Did you use any additional resources while checking the code? If yes, please provide a link or description of your resource.

\$\endgroup\$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.