From bdefcd025604f2c3009fe5e0cc01213c2ba62a6a Mon Sep 17 00:00:00 2001 From: Christophe Besson Date: Tue, 15 Sep 2026 02:16:39 +0200 Subject: feat(hub): usernames are at least 8 characters at registration Existing shorter accounts keep signing in. Test usernames padded to match. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01XuNrwLf5EFWCMHzfoEvnpm --- packages/meshbay-hub/src/meshbay_hub/api/users.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'packages/meshbay-hub/src/meshbay_hub/api/users.py') diff --git a/packages/meshbay-hub/src/meshbay_hub/api/users.py b/packages/meshbay-hub/src/meshbay_hub/api/users.py index 05f58cd..9150909 100644 --- a/packages/meshbay-hub/src/meshbay_hub/api/users.py +++ b/packages/meshbay-hub/src/meshbay_hub/api/users.py @@ -78,6 +78,10 @@ async def _verify_captcha_or_raise(token: str | None, request: Request) -> None: # ── Models ──────────────────────────────────────────────────────────────────── +# Mirrored by USERNAME_MIN_LEN in static/auth-page.js; test_username_floor.py +# holds the two equal. +USERNAME_MIN_LEN = 8 + class RegisterRequest(BaseModel): username: str email: str @@ -92,9 +96,11 @@ class RegisterRequest(BaseModel): @field_validator("username") @classmethod def username_valid(cls, v: str) -> str: + # Registration only. Login, reset and deletion take the name as stored, + # so accounts created under the older 3-character floor keep working. v = v.strip() - if len(v) < 3 or len(v) > 64: - raise ValueError("username must be 3-64 chars") + if len(v) < USERNAME_MIN_LEN or len(v) > 64: + raise ValueError(f"username must be {USERNAME_MIN_LEN}-64 chars") if not v.replace("_", "").replace("-", "").replace(".", "").isalnum(): raise ValueError("username: only letters, digits, -, _, .") return v -- cgit v1.2.3