update encrypted journal prompt to use new messaging functionality

This commit is contained in:
Jonathan Wren 2022-05-28 13:49:54 -07:00
parent ebfc7bd965
commit 71eb7462be
2 changed files with 7 additions and 3 deletions

View file

@ -1,5 +1,4 @@
import base64 import base64
import getpass
import hashlib import hashlib
import logging import logging
import os import os
@ -46,8 +45,12 @@ def decrypt_content(
keychain: str = None, keychain: str = None,
max_attempts: int = 3, max_attempts: int = 3,
) -> str: ) -> 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) 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) result = decrypt_func(password)
# Password is bad: # Password is bad:
if result is None and pwd_from_keychain: if result is None and pwd_from_keychain:
@ -55,7 +58,7 @@ def decrypt_content(
attempt = 1 attempt = 1
while result is None and attempt < max_attempts: while result is None and attempt < max_attempts:
print_msg(Message(MsgText.WrongPasswordTryAgain, MsgStyle.WARNING)) print_msg(Message(MsgText.WrongPasswordTryAgain, MsgStyle.WARNING))
password = getpass.getpass() password = get_pw()
result = decrypt_func(password) result = decrypt_func(password)
attempt += 1 attempt += 1

View file

@ -233,6 +233,7 @@ class MsgText(Enum):
""" """
# --- Password --- # # --- Password --- #
Password = "Password:"
PasswordFirstEntry = "Enter new password: " PasswordFirstEntry = "Enter new password: "
PasswordConfirmEntry = "Enter password again: " PasswordConfirmEntry = "Enter password again: "
PasswordMaxTriesExceeded = "Too many attempts with wrong password" PasswordMaxTriesExceeded = "Too many attempts with wrong password"