Создание и первичная инициализация базы даных успешно завершена. Наполнение демо-данными прошло без ошибок
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+6
-1
@@ -1,4 +1,9 @@
|
||||
def toDict(data) -> dict:
|
||||
def dateToStr(date):
|
||||
if date is None:
|
||||
return None
|
||||
return date.strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
return {
|
||||
c.name: (
|
||||
(
|
||||
@@ -7,7 +12,7 @@ def toDict(data) -> dict:
|
||||
else getattr(data, c.name).toDict()
|
||||
)
|
||||
if not c.name.endswith("_at")
|
||||
else getattr(data, c.name).strftime("%Y-%m-%d %H:%M:%S")
|
||||
else dateToStr(getattr(data, c.name))
|
||||
)
|
||||
for c in data.__table__.columns
|
||||
}
|
||||
|
||||
+23
-9
@@ -1,18 +1,32 @@
|
||||
from passlib.context import CryptContext
|
||||
from argon2 import PasswordHasher
|
||||
from argon2.exceptions import (
|
||||
VerifyMismatchError,
|
||||
VerificationError,
|
||||
InvalidHash,
|
||||
)
|
||||
|
||||
from utils.loggers import logger
|
||||
|
||||
|
||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
||||
pwd_hasher = PasswordHasher(
|
||||
time_cost=3,
|
||||
memory_cost=65536,
|
||||
parallelism=2,
|
||||
)
|
||||
|
||||
|
||||
def pwd_hash(pwd_plant: str) -> str:
|
||||
return pwd_context.encrypt(pwd_plant)
|
||||
def pwd_hash(pwd_plain: str) -> str:
|
||||
pwd_plain = str(pwd_plain)
|
||||
return pwd_hasher.hash(pwd_plain)
|
||||
|
||||
|
||||
def pwd_verify(pwd_plant: str, pwd_hash: str) -> bool:
|
||||
from utils.loggers import logger
|
||||
def pwd_verify(pwd_plain: str, stored_hash: str) -> bool:
|
||||
pwd_plain = str(pwd_plain)
|
||||
|
||||
try:
|
||||
return pwd_context.verify(pwd_plant, pwd_hash)
|
||||
except Exception as e:
|
||||
logger.error(f"Password verification error: {str(e)}")
|
||||
valid = pwd_hasher.verify(stored_hash, pwd_plain)
|
||||
except (VerifyMismatchError, VerificationError, InvalidHash) as e:
|
||||
logger.warning(f"Password verification failed: {e.__class__.__name__}")
|
||||
return False
|
||||
|
||||
return valid
|
||||
|
||||
Reference in New Issue
Block a user