otpauth is One Time Password Authentication, which is usually called as two steps verification. You may have heard it from Google, Dropbox and etc.
Installing otpauth is simple with pip:
$ pip install otpauth
or, with easy_install:
$ easy_install otpauth
Generate and validate an otp code is very simple:
>>> from otpauth import OtpAuth
>>> auth = OtpAuth('secret') # a secret string
>>> auth.hotp() # generate a count based code, default count is 4
330810
>>> auth.valid_hotp(330810)
4
>>> auth.hotp(2) # generate a count based code, count is 2
720111
>>> auth.valid_hotp(720111)
2
>>> auth.totp() # generate a time based code
828657
>>> auth.valid_totp(828657)
True
You can create a QR code for Google Authenticator to scan:
>>> from otpauth import OtpAuth
>>> auth = OtpAuth('secret') # a secret string
>>> s = auth.to_uri('totp', 'Example:foo@bar.baz', 'Foo')
>>> import qrcode
>>> img = qrcode.make(s)
Here is the API reference for otpauth.
One Time Password Authentication.
Parameters: | secret – A secret token for the authentication. |
---|
Generate a HOTP code.
Parameters: | counter – HOTP is a counter based algorithm. |
---|
Generate the otpauth protocal string for Google Authenticator.
Deprecated since version 0.2.0: Use to_uri() instead.
Generate the otpauth protocal string.
Parameters: |
|
---|
Generate a TOTP code.
A TOTP code is an extension of HOTP algorithm.
Parameters: |
|
---|
Valid a HOTP code.
Parameters: |
|
---|
Valid a TOTP code.
Parameters: |
|
---|
Generate a HOTP code.
Parameters: |
|
---|
Generate a TOTP code.
A TOTP code is an extension of HOTP algorithm.
Parameters: |
|
---|
Here is the full history of otpauth.
Released on Dec 18, 2014
Released on Aug 16, 2013
I believe this library is stable now. Someday it will turn into 1.0.0.
First preview release.