This commit is contained in:
@@ -41,15 +41,15 @@ class UserBase(BaseModel):
|
||||
|
||||
|
||||
class UserCreate(UserBase):
|
||||
password: str = Field(..., min_length=8, max_length=70, description="Password (will be truncated to 72 bytes for bcrypt compatibility)")
|
||||
password: str = Field(..., min_length=8, description="Password for user registration")
|
||||
|
||||
@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)")
|
||||
"""Basic validation for password."""
|
||||
# Только проверка минимальной длины
|
||||
if not v or len(v.strip()) < 8:
|
||||
raise ValueError("Password must be at least 8 characters")
|
||||
return v
|
||||
|
||||
|
||||
@@ -102,17 +102,15 @@ class UserResponse(UserBase):
|
||||
class UserLogin(BaseModel):
|
||||
email: Optional[EmailStr] = None
|
||||
username: Optional[str] = None
|
||||
password: str = Field(..., max_length=70, description="Password (will be truncated to 72 bytes for bcrypt compatibility)")
|
||||
password: str = Field(..., min_length=1, description="Password for authentication")
|
||||
|
||||
@field_validator("password")
|
||||
@classmethod
|
||||
def validate_password_bytes(cls, v):
|
||||
"""Ensure password doesn't exceed bcrypt's 72-byte limit."""
|
||||
"""Basic password validation."""
|
||||
if not v or len(v.strip()) == 0:
|
||||
raise ValueError("Password cannot be empty")
|
||||
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)")
|
||||
# Не делаем проверку на максимальную длину - passlib/bcrypt сам справится с ограничениями
|
||||
return v
|
||||
|
||||
@field_validator("username")
|
||||
|
||||
Reference in New Issue
Block a user