update
This commit is contained in:
@@ -41,11 +41,27 @@ def _bcrypt_safe_password(password: str) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def hash_password(password: str) -> str:
|
def hash_password(password: str) -> str:
|
||||||
return pwd_context.hash(_bcrypt_safe_password(password))
|
safe = _bcrypt_safe_password(password)
|
||||||
|
try:
|
||||||
|
return pwd_context.hash(safe)
|
||||||
|
except Exception as e:
|
||||||
|
orig_len = len(password.encode("utf-8"))
|
||||||
|
safe_len = len(safe.encode("utf-8"))
|
||||||
|
raise RuntimeError(
|
||||||
|
f"{str(e)} (orig_bytes_len={orig_len}, safe_bytes_len={safe_len}, safe_type={type(safe).__name__})"
|
||||||
|
) from e
|
||||||
|
|
||||||
|
|
||||||
def verify_password(password: str, password_hash: str) -> bool:
|
def verify_password(password: str, password_hash: str) -> bool:
|
||||||
return pwd_context.verify(_bcrypt_safe_password(password), password_hash)
|
safe = _bcrypt_safe_password(password)
|
||||||
|
try:
|
||||||
|
return pwd_context.verify(safe, password_hash)
|
||||||
|
except Exception as e:
|
||||||
|
orig_len = len(password.encode("utf-8"))
|
||||||
|
safe_len = len(safe.encode("utf-8"))
|
||||||
|
raise RuntimeError(
|
||||||
|
f"{str(e)} (orig_bytes_len={orig_len}, safe_bytes_len={safe_len}, safe_type={type(safe).__name__})"
|
||||||
|
) from e
|
||||||
|
|
||||||
|
|
||||||
def create_access_token(*, user_id: str) -> str:
|
def create_access_token(*, user_id: str) -> str:
|
||||||
|
|||||||
Reference in New Issue
Block a user