From dbe46e8e61f83fc8966bb84a32a5cdaafb6dd8db Mon Sep 17 00:00:00 2001 From: bischoffjeremy <61356201+bischoffjeremy@users.noreply.github.com> Date: Tue, 30 Dec 2025 10:32:33 +0100 Subject: [PATCH] fix: default username to 'admin' if password is set but username is empty (#374) Fixed an issue where hitting save with an empty username would fail silently. This led users to think their changes were saved when they actually weren't. Now it automatically defaults to "admin" if you set a password but leave the username blank, making the save process reliable. Cheers, Your swiss librarian ;) --- cwa_book_downloader/config/security.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cwa_book_downloader/config/security.py b/cwa_book_downloader/config/security.py index 3223f10..c785004 100644 --- a/cwa_book_downloader/config/security.py +++ b/cwa_book_downloader/config/security.py @@ -50,6 +50,7 @@ def _on_save_security(values: Dict[str, Any]) -> Dict[str, Any]: - If new password is provided, validate confirmation and hash it - If password fields are empty, preserve existing hash - Never store raw passwords + - Ensure username is present if password is set Returns: Dict with processed values to save and any validation errors. @@ -63,6 +64,13 @@ def _on_save_security(values: Dict[str, Any]) -> Dict[str, Any]: # If password is provided, validate and hash it if password: + if not values.get("BUILTIN_USERNAME"): + return { + "error": True, + "message": "Username cannot be empty", + "values": values + } + if password != password_confirm: return { "error": True,