Huy Minh Ha

Software development, Tech and other stuff

Sun 02 October 2016

Generate one-time password from the command line

Posted by Ha.Minh in Programming   

One-time password is pretty common these days for any type of account that offers two-factor authentication. We can use an app to generate OTP but it would be troublesome if we lost the app or the phone. Fortunately there's a simple way to generate OTP programmatically using libraries such as Python OneTimePass.

First, install OneTimePass with pip:

pip install onetimepass

Then you get the secret generated from the service provider you're using. Normally it would be a time-based token, such as the ones you use for Google Authenticator.

To get time-based token you invoke it like this:

import onetimepass as otp

my_secret = 'MFRGGZDFMZTWQ2LK'
my_token = otp.get_totp(my_secret)
print my_token

Remember to store your secret safely.


    
 
 

Comments