Forget passwords clears every stored admin password in one step

The reporter of #28 asked for a way to clear one or all of the stored admin
passwords. Del in the node picker forgets one. This adds the other: a
"Forget passwords" row in the Managed nodes section of the menu, behind the
red typed confirm (type FORGET), which names the nodes it will forget. It
also forgets the password of a node that is no longer a contact, which no
list shows. With nothing stored, it says so and asks nothing.

On the CLI it is `forget-admin-passwords --yes`: without --yes it is a usage
error, and with it the answer lists the nodes it forgot (NAME, LAST_LOGIN,
KEY). It exits 5 when nothing was stored, and works with no device.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5.5 committed 2026-11-04 01:59:35 -05:00
1 parent e8a3b439cd
commit 4356bc9012
8 files changed
+406 -7

No files matched your search

+23
View File
@@ -182,6 +182,29 @@ class AdminStore:
if records.pop(admin_key(node), None) is not None:
self._write(records)
def credentials(self) -> list[AdminCredential]:
"""Return all the remembered passwords, in the order of the file.
The list includes the password of a node that the device does not know any more,
because the store keys a password by the node and not by the contact list.
"""
return list(self._load().values())
def forget_all(self) -> list[AdminCredential]:
"""Delete all the remembered passwords.
Each next login asks for the password again. The method writes the file only when
it held a password.
Returns:
The credentials that the store forgot. The list is empty when the store held
none.
"""
records = self._load()
if records:
self._write({})
return list(records.values())
def _write(self, records: dict[str, AdminCredential]) -> None:
"""Store ``records`` atomically, with owner-only permissions where they are supported."""
data = {key: record.to_json() for key, record in records.items()}