diff --git a/features/encryption.feature b/features/encryption.feature index 43d07c26..74eca5b8 100644 --- a/features/encryption.feature +++ b/features/encryption.feature @@ -16,6 +16,8 @@ Scenario: Encrypting a journal Given we use the config "basic.json" When we run "jrnl --encrypt" and enter "swordfish" + Then we should see the message "Confirm Password:" + When we enter "swordfish" Then we should see the message "Journal encrypted" and the config for journal "default" should have "encrypt" set to "bool:True" When we run "jrnl -n 1" and enter "swordfish" @@ -30,7 +32,9 @@ Scenario: Storing a password in Keychain Given we use the config "multiple.json" When we run "jrnl simple --encrypt" and enter "sabertooth" - When we set the keychain password of "simple" to "sabertooth" + Then we should see the message "Confirm Password:" + When we enter "sabertooth" + and we set the keychain password of "simple" to "sabertooth" Then the config for journal "simple" should have "encrypt" set to "bool:True" When we run "jrnl simple -n 1" Then we should not see the message "Password" diff --git a/jrnl/cli.py b/jrnl/cli.py index 35764734..f6799a00 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -73,7 +73,14 @@ def guess_mode(args, config): def encrypt(journal, filename=None): """ Encrypt into new file. If filename is not set, we encrypt the journal file itself. """ - password = util.getpass("Enter new password: ") + confirmed_password = False + while confirmed_password == False: + password = util.getpass("Enter new password: ") + password_conf = util.getpass("Confirm password: ") + if password == password_conf: + confirmed_password = True + else: + print("Password and confirmation did not match, try again.") journal.make_key(password) journal.config['encrypt'] = True journal.write(filename) diff --git a/jrnl/install.py b/jrnl/install.py index 138cb826..23153476 100644 --- a/jrnl/install.py +++ b/jrnl/install.py @@ -69,7 +69,14 @@ def install_jrnl(config_path='~/.jrnl_config'): # Encrypt it? if module_exists("Crypto"): - password = getpass.getpass("Enter password for journal (leave blank for no encryption): ") + confirmed_password = False + while confirmed_password == False: + password = getpass.getpass("Enter password for journal (leave blank for no encryption): ") + password_conf = getpass.getpass("Confirm password: ") + if password == password_conf: + confirmed_password = True + else: + print("Password and confirmation did not match, try again.") if password: default_config['encrypt'] = True if util.yesno("Do you want to store the password in your keychain?", default=True):