Generate one-time password from the command line

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:

1
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:

1
2
3
4
5
import onetimepass as otp

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

Remember to store your secret safely.

comments powered by Disqus
All content is licensed under CC BY-NC-SA 4.0
Built with Hugo
Theme Stack designed by Jimmy