bcrypt pwd legth decreased <70
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-09-26 06:58:07 +09:00
parent 24c1a0c85c
commit 31c1644ec2
3 changed files with 42 additions and 5 deletions

View File

@@ -41,7 +41,16 @@ class UserBase(BaseModel):
class UserCreate(UserBase):
password: str = Field(..., min_length=8, max_length=100)
password: str = Field(..., min_length=8, max_length=70, description="Password (will be truncated to 72 bytes for bcrypt compatibility)")
@field_validator("password")
@classmethod
def validate_password_bytes(cls, v):
"""Ensure password doesn't exceed bcrypt's 72-byte limit."""
password_bytes = v.encode('utf-8')
if len(password_bytes) > 72:
raise ValueError("Password is too long when encoded as UTF-8 (max 72 bytes for bcrypt)")
return v
class UserUpdate(BaseModel):
@@ -93,7 +102,16 @@ class UserResponse(UserBase):
class UserLogin(BaseModel):
email: Optional[EmailStr] = None
username: Optional[str] = None
password: str
password: str = Field(..., max_length=70, description="Password (will be truncated to 72 bytes for bcrypt compatibility)")
@field_validator("password")
@classmethod
def validate_password_bytes(cls, v):
"""Ensure password doesn't exceed bcrypt's 72-byte limit."""
password_bytes = v.encode('utf-8')
if len(password_bytes) > 72:
raise ValueError("Password is too long when encoded as UTF-8 (max 72 bytes for bcrypt)")
return v
class Token(BaseModel):