35
loading...
This website collects cookies to deliver better user experience
Time based codes | Counter based codes |
---|---|
Time based codes changes depending on time. 🕖 | Counter based codes change depending on number of successful sign-in(s). ✔️ |
No need of adding counter every time in client side. | After every successful login, counter must be increased by one in server side as well as client side. |
pip install onetimepass
).from onetimepass import valid_totp
from secrets import choice
def generate_secret(): # Function to return a random string with length 16.
secret = ''
while len(secret) < 16:
secret += choice('ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567')
return secret
secret = generate_secret()
print('Enter the following secret in your authenticator app: ', secret)
print("""
Instructions for saving this secret it Google Authenticator:
1. Open Google Authenticator.
2. Click plus icon at the right bottom.
3. Click Enter a setup key.
4. Enter an Account name of your choice and enter the secret provided above.
5. Click Add.
""")
while True:
otp = int(input('Please enter the otp generated by your authenticator app: '))
authenticated = valid_totp(otp, secret)
if authenticated:
print('Correct otp, Authenticated!')
elif not authenticated:
print('Wrong otp, please try again.')
from onetimepass import valid_hotp
from secrets import choice
def generate_secret(): # Function to return a random string with length 16.
secret = ''
while len(secret) < 16:
secret += choice('ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567')
return secret
secret = generate_secret()
print('Enter the following secret in your authenticator app: ', secret)
print("""
Instructions for saving this secret it Google Authenticator:
1. Open Google Authenticator.
2. Click plus icon at the right bottom.
3. Click Enter a setup key.
4. Enter an Account name of your choice and enter the secret provided above.
5. Click Add.
""")
while True:
counter = 0
otp = int(input('Please enter the otp generated by your authenticator app: '))
authenticated = valid_hotp(otp, secret)
if authenticated:
print('Correct otp, Authenticated!')
counter += 1
elif not authenticated:
print('Wrong otp, please try again.')