pschmitt / pkp

Straightforward CLI for KeePass - powered by pykeepass
GNU General Public License v3.0
3 stars 1 forks source link

Support TOTP (enhancement) #26

Open RaghavRao opened 2 years ago

RaghavRao commented 2 years ago

pkp.py.txt Hi! Sorry on mobile so can't make a proper pull request. I use KP a lot for TOTP instead of Google Authenticator here's my proof of concept for TOTP support for the show command:

import pyotp

And in the show command:

    print_field(
        "TOTP Seed", entry.get_custom_property("TOTP Seed"), skip_empty=skip_empty, color=color
    )
    print_field(
        "TOTP Settings", entry.get_custom_property("TOTP Settings"), skip_empty=skip_empty, color=color
    )

    if entry.get_custom_property("TOTP Seed") and entry.get_custom_property("TOTP Settings") == "30;6":
        print_field(
                "TOTP", pyotp.TOTP(entry.get_custom_property("TOTP Seed")).now(), skip_empty=skip_empty, color=color
    )

It works with show vs show -a as intended and also mirrors the KeePassXC behavior (only show TOTP field if Seed and Settings are populated)

Nonstandard TOTP Settings aren't handled with this

Thanks for making a usable (and readable!) CLI, it makes termux much more usable as my launcher

pschmitt commented 2 years ago

Mind opening a propper PR? :angel: