Skip to content

Instantly share code, notes, and snippets.

@Ajnasz
Created November 22, 2018 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ajnasz/51d4059eab106692c09b35a413e1c42f to your computer and use it in GitHub Desktop.
Save Ajnasz/51d4059eab106692c09b35a413e1c42f to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2
# Python script to generate TOTP qrcodes from keepass database to scan into
# authenticator app
# Required libraries:
# https://github.com/lincolnloop/python-qrcode
# https://github.com/pschmitt/pykeepass
from pykeepass import PyKeePass
import qrcode
import os
kp = PyKeePass('/path/to/passwords.kdbx', password='password')
entries = kp.find_entries(title='.*', regex=True)
filtered_entries = filter(lambda entry: entry.get_custom_property('TOTP Seed') != None, entries)
for i in filtered_entries:
raw_input("Press enter")
os.system('clear')
qrcodedata="otpauth://totp/%s?secret=%s&issuer=%s" % (i.username, i.get_custom_property('TOTP Seed').strip(), i.title)
qr = qrcode.QRCode()
qr.add_data(qrcodedata)
qr.print_ascii(tty=True)
print "%s %s" % (i.title, i.username)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment