Created
August 30, 2016 21:11
-
-
Save onjin/97fc4327a23128f2ea621deca5addc91 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
"""Google Authenticator integration example | |
$ pip install otpauth qrcode pillow | |
""" | |
import qrcode | |
from otpauth import OtpAuth | |
SECRET = 'some secret' | |
auth = OtpAuth(SECRET) | |
# generate qrcode to scan with Googla Authenticator app | |
s = auth.to_uri('totp', '[email protected]', 'Test') | |
img = qrcode.make(s) | |
img.show() | |
# display current code | |
print 'Current: {}'.format(auth.totp()) | |
# ask for and verify given code | |
while True: | |
code = raw_input('Auth code:') | |
print 'Verification {}: {}'.format(code, auth.valid_totp(code)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment