mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-06-29 14:06:14 +02:00
Add password confirmation dialog
This commit is contained in:
parent
70c946bc13
commit
8eb185f8a2
6 changed files with 66 additions and 25 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
10
jrnl/util.py
10
jrnl/util.py
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue