From 63292e291d7ed910eda3b1a0fd91ca736a4e5370 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Thu, 11 May 2023 15:48:34 -0400 Subject: [PATCH] Hide passwords in password-only entries, ensure entry reader spacing is consistent Former-commit-id: 30613971d642819f7ed40f777c966237ff592c1f Former-commit-id: f7654f02d6c6663109c481415b2c7d4f91613a88 --- lib/sshyp.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/sshyp.py b/lib/sshyp.py index 2882774..46220a5 100755 --- a/lib/sshyp.py +++ b/lib/sshyp.py @@ -44,19 +44,19 @@ def entry_list_gen(_directory=f"{home}/.local/share/sshyp/"): # displays the contents of an entry in a readable format def entry_reader(_decrypted_entry): _entry_lines, _notes_flag = open(_decrypted_entry, 'r').readlines(), 0 + if pass_show: + _entry_password = f'\u001b[38;5;10m{_entry_lines[0]}\u001b[0m' + else: + _entry_password = f'\u001b[38;5;3mend command in "--show" or "-s" to view\u001b[0m\n' print() for _num in range(len(_entry_lines)): try: if _num == 0 and _entry_lines[1] != '\n': - print(f"\u001b[38;5;15;48;5;238musername:\u001b[0m\n{_entry_lines[1]}\n") + print(f"\u001b[38;5;15;48;5;238musername:\u001b[0m\n{_entry_lines[1]}") elif _num == 1 and _entry_lines[0] != '\n': - if pass_show: - print(f"\u001b[38;5;15;48;5;238mpassword:\u001b[0m\n\u001b[38;5;10m{_entry_lines[0]}\u001b[0m\n") - else: - print('\u001b[38;5;15;48;5;238mpassword:\u001b[0m\n\u001b[38;5;3mend command in "--show" or "-s" ' - 'to view\u001b[0m\n') + print(f"\u001b[38;5;15;48;5;238mpassword:\u001b[0m\n{_entry_password}") elif _num == 2 and _entry_lines[2] != '\n': - print(f"\u001b[38;5;15;48;5;238murl:\u001b[0m\n{_entry_lines[_num]}\n") + print(f"\u001b[38;5;15;48;5;238murl:\u001b[0m\n{_entry_lines[_num]}") elif _num >= 3 and _entry_lines[_num] != '\n' and _notes_flag != 1: _notes_flag = 1 print('\u001b[38;5;15;48;5;238mnotes:\u001b[0m\n' + _entry_lines[_num].strip('\n')) @@ -69,7 +69,9 @@ def entry_reader(_decrypted_entry): print() except IndexError: if _num == 0: - print(f"\u001b[38;5;15;48;5;238mpassword:\u001b[0m\n{_entry_lines[0]}\n") + print(f"\u001b[38;5;15;48;5;238mpassword:\u001b[0m\n{_entry_password}") + if pass_show: + print() # generates and returns a random string based on input