Skip to content

Instantly share code, notes, and snippets.

@mtfurlan
Last active August 30, 2021 20:13
Show Gist options
  • Save mtfurlan/821722424f94e3f909b88bc617dcd44e to your computer and use it in GitHub Desktop.
Save mtfurlan/821722424f94e3f909b88bc617dcd44e to your computer and use it in GitHub Desktop.
read google authenitcator database and generate codes
#!/usr/bin/env python3
# read google authenticator database and output TOTP codes.
# /data/data/com.google.android.apps.authenticator2/databases/databases
#import qrcode
import sqlite3
import pyotp
from tabulate import tabulate
conn = sqlite3.connect('databases')
c = conn.cursor()
output = []
for idx, (email, secret, issuer) in enumerate(c.execute("SELECT email,secret,issuer FROM accounts").fetchall()):
# if you want to make a QR code to import it elsewhere I guess this will do that?
# https://gist.github.com/jbinto/8876658#gistcomment-1522362
#url = 'otpauth://totp/{}?secret={}&issuer={}'.format(email, secret, issuer)
#im = qrcode.make(url)
#im.save('{}.png'.format(idx))
totp = pyotp.TOTP(secret)
code = totp.now()
#print(f"{email}: {code}")
output.append([email, code]);
print(tabulate(output, headers=['service', 'code']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment