2019-06-28 02:39:56 +00:00
|
|
|
|
#!/usr/bin/env python
|
|
|
|
|
# Two-factor Authentication (2FA) Helper - Developed by acidvegas in Python (https://acid.vegas/random)
|
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
Requirements:
|
|
|
|
|
pyotp (https://pypi.org/project/pyotp/)
|
|
|
|
|
qrcode (https://pypi.org/project/qrcode/)
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
import io, sys, time
|
|
|
|
|
|
|
|
|
|
try:
|
2021-02-13 19:35:45 +00:00
|
|
|
|
import pyotp
|
2019-06-28 02:39:56 +00:00
|
|
|
|
except ImportError:
|
|
|
|
|
raise SystemExit('missing required \'pyotp\' module! (https://pypi.org/project/pyotp/)')
|
|
|
|
|
try:
|
|
|
|
|
import qrcode
|
|
|
|
|
except ImportError:
|
|
|
|
|
raise SystemExit('missing required \'qrcode\' module! (https://pypi.org/project/qrcode/)')
|
|
|
|
|
|
|
|
|
|
def qrgen(data):
|
|
|
|
|
stdout = sys.stdout
|
|
|
|
|
sys.stdout = io.StringIO()
|
|
|
|
|
qr = qrcode.QRCode(border=1)
|
|
|
|
|
qr.add_data(data)
|
|
|
|
|
qr.make(fit=True)
|
|
|
|
|
qr.print_ascii(invert=True)
|
|
|
|
|
output = sys.stdout.getvalue()
|
|
|
|
|
sys.stdout = stdout
|
|
|
|
|
return output
|
|
|
|
|
|
|
|
|
|
name = input('name : ')
|
|
|
|
|
issuer = input('issuer : ')
|
|
|
|
|
secret = input('secret : ') or pyotp.random_base32()
|
|
|
|
|
uri = pyotp.totp.TOTP(secret).provisioning_uri(name, issuer)
|
|
|
|
|
qr = qrgen(uri).replace(' ', ' ')[:-1]
|
|
|
|
|
max_len = len(qr.split('\n')[1])
|
2019-08-02 02:15:39 +00:00
|
|
|
|
print(f'{uri}\n{qr}')
|
2019-06-28 02:39:56 +00:00
|
|
|
|
del name, issuer, uri, qr
|
|
|
|
|
while True:
|
|
|
|
|
code = pyotp.TOTP(secret).now()
|
|
|
|
|
seconds = int(time.strftime('%S'))
|
|
|
|
|
remain = 60-seconds if seconds >= 30 else 30-seconds
|
2019-08-02 02:15:39 +00:00
|
|
|
|
print(f'{code} ({remain})'.center(max_len), end='\r')
|
2019-06-28 02:39:56 +00:00
|
|
|
|
time.sleep(1)
|