diff --git a/backend/open_webui/constants.py b/backend/open_webui/constants.py index 86d87a2c3..95c54a0d2 100644 --- a/backend/open_webui/constants.py +++ b/backend/open_webui/constants.py @@ -31,6 +31,7 @@ class ERROR_MESSAGES(str, Enum): USERNAME_TAKEN = ( "Uh-oh! This username is already registered. Please choose another username." ) + PASSWORD_TOO_LONG = "Uh-oh! The password you entered is too long. Please make sure your password is less than 72 bytes long." COMMAND_TAKEN = "Uh-oh! This command is already registered. Please choose another command string." FILE_EXISTS = "Uh-oh! This file is already registered. Please choose another file." diff --git a/backend/open_webui/routers/auths.py b/backend/open_webui/routers/auths.py index 67c2e9f2a..7905799e6 100644 --- a/backend/open_webui/routers/auths.py +++ b/backend/open_webui/routers/auths.py @@ -454,6 +454,13 @@ async def signup(request: Request, response: Response, form_data: SignupForm): # Disable signup after the first user is created request.app.state.config.ENABLE_SIGNUP = False + # The password passed to bcrypt must be 72 bytes or fewer. If it is longer, it will be truncated before hashing. + if len(form_data.password.encode("utf-8")) > 72: + raise HTTPException( + status.HTTP_400_BAD_REQUEST, + detail=ERROR_MESSAGES.PASSWORD_TOO_LONG, + ) + hashed = get_password_hash(form_data.password) user = Auths.insert_new_auth( form_data.email.lower(),