From 71eb7462bef809f4c0fb00f65b9c1d28ef902871 Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Sat, 28 May 2022 13:49:54 -0700 Subject: [PATCH] update encrypted journal prompt to use new messaging functionality --- jrnl/EncryptedJournal.py | 9 ++++++--- jrnl/messages.py | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/jrnl/EncryptedJournal.py b/jrnl/EncryptedJournal.py index 69c73681..dbd2c501 100644 --- a/jrnl/EncryptedJournal.py +++ b/jrnl/EncryptedJournal.py @@ -1,5 +1,4 @@ import base64 -import getpass import hashlib import logging import os @@ -46,8 +45,12 @@ def decrypt_content( keychain: str = None, max_attempts: int = 3, ) -> str: + get_pw = lambda: print_msg( + Message(MsgText.Password, MsgStyle.PROMPT), get_input=True, hide_input=True + ) + pwd_from_keychain = keychain and get_keychain(keychain) - password = pwd_from_keychain or getpass.getpass() + password = pwd_from_keychain or get_pw() result = decrypt_func(password) # Password is bad: if result is None and pwd_from_keychain: @@ -55,7 +58,7 @@ def decrypt_content( attempt = 1 while result is None and attempt < max_attempts: print_msg(Message(MsgText.WrongPasswordTryAgain, MsgStyle.WARNING)) - password = getpass.getpass() + password = get_pw() result = decrypt_func(password) attempt += 1 diff --git a/jrnl/messages.py b/jrnl/messages.py index ef763797..7c40b60a 100644 --- a/jrnl/messages.py +++ b/jrnl/messages.py @@ -233,6 +233,7 @@ class MsgText(Enum): """ # --- Password --- # + Password = "Password:" PasswordFirstEntry = "Enter new password: " PasswordConfirmEntry = "Enter password again: " PasswordMaxTriesExceeded = "Too many attempts with wrong password"