mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2025-08-15 11:11:16 +08:00
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:
@ -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,
|
||||
|
Reference in New Issue
Block a user