Skip to content

Instantly share code, notes, and snippets.

@onjin
Created August 30, 2016 21:11
Show Gist options
  • Save onjin/97fc4327a23128f2ea621deca5addc91 to your computer and use it in GitHub Desktop.
Save onjin/97fc4327a23128f2ea621deca5addc91 to your computer and use it in GitHub Desktop.
# -*- 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