Skip to content

Instantly share code, notes, and snippets.

@Ajnasz

Ajnasz/main.py

Created Nov 22, 2018
Embed
What would you like to do?
#!/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