Implement password validation mechanism (#632)

* Implement password validation mechanism

* Add invalid password reason

* Always pass user in password validator

* Add password validation documentation
This commit is contained in:
François Voron
2021-05-17 08:58:23 +02:00
committed by GitHub
parent 5b76d5d90a
commit 5267e605f4
18 changed files with 320 additions and 34 deletions

View File

@ -1,4 +1,4 @@
from typing import Awaitable, Type
from typing import Any, Awaitable, Union, Type
try:
from typing import Protocol
@ -12,18 +12,34 @@ from fastapi_users.db import BaseUserDatabase
from fastapi_users.password import get_password_hash
class UserAlreadyExists(Exception):
class FastAPIUsersException(Exception):
pass
class UserNotExists(Exception):
class UserAlreadyExists(FastAPIUsersException):
pass
class UserAlreadyVerified(Exception):
class UserNotExists(FastAPIUsersException):
pass
class UserAlreadyVerified(FastAPIUsersException):
pass
class InvalidPasswordException(FastAPIUsersException):
def __init__(self, reason: Any) -> None:
self.reason = reason
class ValidatePasswordProtocol(Protocol): # pragma: no cover
def __call__(
self, password: str, user: Union[models.BaseUserCreate, models.BaseUserDB]
) -> Awaitable[None]:
pass
class CreateUserProtocol(Protocol): # pragma: no cover
def __call__(
self,