This commit is contained in:
@@ -108,10 +108,21 @@ class UserLogin(BaseModel):
|
||||
@classmethod
|
||||
def validate_password_bytes(cls, v):
|
||||
"""Ensure password doesn't exceed bcrypt's 72-byte limit."""
|
||||
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)")
|
||||
return v
|
||||
|
||||
@field_validator("username")
|
||||
@classmethod
|
||||
def validate_login_fields(cls, v, info):
|
||||
"""Ensure at least email or username is provided."""
|
||||
email = info.data.get('email')
|
||||
if not email and not v:
|
||||
raise ValueError("Either email or username must be provided")
|
||||
return v
|
||||
|
||||
|
||||
class Token(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user