Catch invalid passwords in keepass
This commit is contained in:
parent
1a9829b93b
commit
04fd42c63b
@ -7,6 +7,7 @@ import os
|
|||||||
import os.path
|
import os.path
|
||||||
import shlex
|
import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
@ -145,8 +146,14 @@ class Keepass(PasswordManager):
|
|||||||
def get_password(self, password_name: str) -> str:
|
def get_password(self, password_name: str) -> str:
|
||||||
import pykeepass # already made sure it is avaiable above
|
import pykeepass # already made sure it is avaiable above
|
||||||
|
|
||||||
password = getpass.getpass(f"KeePass password for database {self.database}: ")
|
while True:
|
||||||
kp = pykeepass.PyKeePass(self.database, password=password)
|
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)
|
entry = kp.find_entries(username=password_name, first=True)
|
||||||
if not entry:
|
if not entry:
|
||||||
raise SystemExit(f"no KeePass entry for {password_name!r} found")
|
raise SystemExit(f"no KeePass entry for {password_name!r} found")
|
||||||
|
Loading…
Reference in New Issue
Block a user