From ff2a0025c3f67b802d87b42d6eb89044d0dba6ef Mon Sep 17 00:00:00 2001 From: charles-gauthereau Date: Wed, 18 Nov 2026 15:48:39 +0100 Subject: [PATCH] fix(settings): accept 16+ character admin passwords without composition rules --- services/settings.py | 5 ++++- tests/services/settings.py | 10 +++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/services/settings.py b/services/settings.py index fba5f65..5db7b52 100644 --- a/services/settings.py +++ b/services/settings.py @@ -11,6 +11,8 @@ def strong_password(value: str) -> str: + if len(value) >= 16: + return value checks = ( (len(value) >= 8, "at least 8 characters"), (re.search(r"[a-z]", value), "a lowercase letter"), @@ -21,7 +23,8 @@ def strong_password(value: str) -> str: missing = [label for ok, label in checks if not ok] if missing: raise ValidationError( - "Password too weak.", hint="It needs " + ", ".join(missing) + "." + "Password too weak.", + hint="It needs " + ", ".join(missing) + ", or use at least 16 characters.", ) return value diff --git a/tests/services/settings.py b/tests/services/settings.py index 3c5c802..9f618f2 100644 --- a/tests/services/settings.py +++ b/tests/services/settings.py @@ -13,8 +13,12 @@ def _setting(kind, default=None): return cfg.Setting(Field("x", "X", kind, default=default), "X", "s") -def strong_password_accepts(): - assert cfg.strong_password("Abcdef1!") == "Abcdef1!" +@pytest.mark.parametrize( + "value", + ["Abcdef1!", "Abcdefgh12345678", "9f86d081884c7d659a2feaa0c55ad015"], +) +def strong_password_accepts(value): + assert cfg.strong_password(value) == value @pytest.mark.parametrize( @@ -38,7 +42,7 @@ def strong_password_lists_every_missing_rule(): cfg.strong_password("") assert exc.value.hint == ( "It needs at least 8 characters, a lowercase letter, an uppercase letter, " - "a digit, a special character." + "a digit, a special character, or use at least 16 characters." )