Skip to content

Commit 38bf0b6

Browse files
authored
feat: Add new ENV VAR for custom error message on error on signup / password change due to password not meeting requirements (open-webui#20650)
* add env var for custom auth pw message * Update auth.py * Update auth.py
1 parent 6ae3ddd commit 38bf0b6

3 files changed

Lines changed: 8 additions & 1 deletion

File tree

backend/open_webui/env.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ def parse_section(section):
455455
r"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\w\s]).{8,}$"
456456
)
457457

458+
PASSWORD_VALIDATION_HINT = os.environ.get("PASSWORD_VALIDATION_HINT", "")
459+
458460

459461
BYPASS_MODEL_ACCESS_CONTROL = (
460462
os.environ.get("BYPASS_MODEL_ACCESS_CONTROL", "False").lower() == "true"

backend/open_webui/routers/auths.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,8 @@ async def signup(
813813
}
814814
else:
815815
raise HTTPException(500, detail=ERROR_MESSAGES.CREATE_USER_ERROR)
816+
except HTTPException:
817+
raise
816818
except Exception as err:
817819
log.error(f"Signup error: {str(err)}")
818820
raise HTTPException(500, detail="An internal error occurred during signup.")
@@ -954,6 +956,8 @@ async def add_user(
954956
}
955957
else:
956958
raise HTTPException(500, detail=ERROR_MESSAGES.CREATE_USER_ERROR)
959+
except HTTPException:
960+
raise
957961
except Exception as err:
958962
log.error(f"Add user error: {str(err)}")
959963
raise HTTPException(

backend/open_webui/utils/auth.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
ENABLE_PASSWORD_VALIDATION,
3434
OFFLINE_MODE,
3535
LICENSE_BLOB,
36+
PASSWORD_VALIDATION_HINT,
3637
PASSWORD_VALIDATION_REGEX_PATTERN,
3738
REDIS_KEY_PREFIX,
3839
pk,
@@ -173,7 +174,7 @@ def validate_password(password: str) -> bool:
173174

174175
if ENABLE_PASSWORD_VALIDATION:
175176
if not PASSWORD_VALIDATION_REGEX_PATTERN.match(password):
176-
raise Exception(ERROR_MESSAGES.INVALID_PASSWORD())
177+
raise Exception(ERROR_MESSAGES.INVALID_PASSWORD(PASSWORD_VALIDATION_HINT))
177178

178179
return True
179180

0 commit comments

Comments
 (0)