Keep TOTP retrieval active

This commit is contained in:
thePR0M3TH3AN
2025-07-03 10:17:42 -04:00
parent 7e83a74a64
commit 3d65800eb2
2 changed files with 21 additions and 6 deletions

View File

@@ -1014,13 +1014,24 @@ class PasswordManager:
period = int(entry.get("period", 30))
notes = entry.get("notes", "")
print(colored(f"Retrieving 2FA code for '{label}'.", "cyan"))
print(colored("Press 'b' then Enter to return to the menu.", "cyan"))
try:
code = self.entry_manager.get_totp_code(index, self.parent_seed)
print(colored("\n[+] Retrieved 2FA Code:\n", "green"))
print(colored(f"Code: {code}", "yellow"))
if notes:
print(colored(f"Notes: {notes}", "cyan"))
TotpManager.print_progress_bar(period)
while True:
code = self.entry_manager.get_totp_code(index, self.parent_seed)
print(colored("\n[+] Retrieved 2FA Code:\n", "green"))
print(colored(f"Label: {label}", "cyan"))
print(colored(f"Code: {code}", "yellow"))
if notes:
print(colored(f"Notes: {notes}", "cyan"))
TotpManager.print_progress_bar(period)
try:
if sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
user_input = sys.stdin.readline().strip().lower()
if user_input == "b":
break
except KeyboardInterrupt:
print()
break
except Exception as e:
logging.error(f"Error generating TOTP code: {e}", exc_info=True)
print(colored(f"Error: Failed to generate TOTP code: {e}", "red"))

View File

@@ -43,6 +43,10 @@ def test_handle_retrieve_totp_entry(monkeypatch, capsys):
monkeypatch.setattr("builtins.input", lambda *a, **k: "0")
monkeypatch.setattr(pm.entry_manager, "get_totp_code", lambda *a, **k: "123456")
monkeypatch.setattr(TotpManager, "print_progress_bar", lambda period: None)
monkeypatch.setattr(
"password_manager.manager.select.select",
lambda *a, **k: (_ for _ in ()).throw(KeyboardInterrupt()),
)
pm.handle_retrieve_entry()
out = capsys.readouterr().out