Catch invalid passwords in keepass
This commit is contained in:
parent
c42bef6f02
commit
fa128a9cea
@ -5,6 +5,7 @@ import dataclasses
|
||||
import getpass
|
||||
import os
|
||||
import os.path
|
||||
import sys
|
||||
import shlex
|
||||
import subprocess
|
||||
import typing
|
||||
@ -145,8 +146,14 @@ class Keepass(PasswordManager):
|
||||
def get_password(self, password_name: str) -> str:
|
||||
import pykeepass # already made sure it is avaiable above
|
||||
|
||||
password = getpass.getpass(f"KeePass password for database {self.database}: ")
|
||||
kp = pykeepass.PyKeePass(self.database, password=password)
|
||||
while True:
|
||||
try:
|
||||
password = getpass.getpass(f"KeePass password for database {self.database}: ")
|
||||
kp = pykeepass.PyKeePass(self.database, password=password)
|
||||
break
|
||||
except pykeepass.exceptions.CredentialsError:
|
||||
print("Invalid password", file=sys.stderr)
|
||||
|
||||
entry = kp.find_entries(username=password_name, first=True)
|
||||
if entry:
|
||||
return entry.password # type: ignore
|
||||
|
Loading…
Reference in New Issue
Block a user