Fix #396: add password validation example

This commit is contained in:
François Voron
2020-12-07 07:57:22 +01:00
parent 475c66801c
commit 42340d992b

View File

@@ -40,6 +40,23 @@ class UserDB(User, models.BaseUserDB):
You can of course add you own properties there to fit to your needs!
## Password validation
**FastAPI Users** doesn't provide a default password validation, but you can implement it easily with a [Pydantic validator](https://pydantic-docs.helpmanual.io/usage/validators/) on the `UserCreate` class. Here is a simple example to check if the password is at least six characters long:
```py
from fastapi_users import models
from pydantic import validator
class UserCreate(models.BaseUserCreate):
@validator('password')
def valid_password(cls, v: str):
if len(v) < 6:
raise ValueError('Password should be at least 6 characters')
return v
```
## Next steps
Depending on your database backend, database configuration will differ a bit.