Add password confirmation dialog

This commit is contained in:
Peter Schmidbauer 2019-10-31 21:22:50 +01:00
parent 70c946bc13
commit 8eb185f8a2
6 changed files with 66 additions and 25 deletions

View file

@ -38,7 +38,7 @@ class EncryptedJournal(Journal.Journal):
filename = filename or self.config['journal']
if not os.path.exists(filename):
password = util.getpass("Enter password for new journal: ")
password = util.create_password()
if password:
if util.yesno("Do you want to store the password in your keychain?", default=True):
util.set_keychain(self.name, password)

View file

@ -78,7 +78,7 @@ def encrypt(journal, filename=None):
""" Encrypt into new file. If filename is not set, we encrypt the journal file itself. """
from . import EncryptedJournal
journal.config['password'] = util.getpass("Enter new password: ")
journal.config['password'] = util.create_password()
journal.config['encrypt'] = True
new_journal = EncryptedJournal.EncryptedJournal(None, **journal.config)

View file

@ -37,12 +37,18 @@ class UserAbort(Exception):
pass
getpass = gp.getpass
def create_password():
while True:
pw = gp.getpass("Enter password for new journal: ")
if pw == gp.getpass("Enter password again: "):
return pw
print("Passwords did not match, please try again", file=sys.stderr)
def get_password(validator, keychain=None, max_attempts=3):
pwd_from_keychain = keychain and get_keychain(keychain)
password = pwd_from_keychain or getpass()
password = pwd_from_keychain or gp.getpass()
result = validator(password)
# Password is bad:
if result is None and pwd_from_keychain: