implemented postgres support in repositories

This commit is contained in:
Brian Bjarke Jensen
2025-11-11 18:52:19 +01:00
parent 65655db034
commit e7ed89e04e
31 changed files with 364 additions and 236 deletions
+10
View File
@@ -0,0 +1,10 @@
"""Utility functions for the baby monitor application."""
from .hash_password import hash_password
from .verify_child_access import verify_child_access
from .verify_password import verify_password
__all__ = [
"verify_child_access",
"hash_password",
"verify_password",
]
+17
View File
@@ -0,0 +1,17 @@
"""Definition of hash_password function."""
import bcrypt
def hash_password(password: str) -> str:
"""Hash a password using bcrypt.
Args:
password: Plain text password to hash
Returns:
Hashed password as a string
"""
salt = bcrypt.gensalt()
hashed: bytes = bcrypt.hashpw(password.encode("utf-8"), salt)
return hashed.decode("utf-8")
@@ -1,11 +1,13 @@
"""Access control utility functions for verifying resource ownership."""
"""Definition of verify_child_access function."""
from fastapi import HTTPException
from baby_monitor.repositories.child.sqlite_child import SQLiteChildRepository
from baby_monitor.repositories.interfaces import (
ChildRepositoryInterface,
)
def verify_child_access(
child_repo: SQLiteChildRepository, child_id: int, user_id: int
child_repo: ChildRepositoryInterface, child_id: int, user_id: int
) -> None:
"""Verify that user has access to the child.
@@ -1,22 +1,8 @@
"""Password hashing utilities using bcrypt."""
"""Definition of verify_password function."""
import bcrypt
def hash_password(password: str) -> str:
"""Hash a password using bcrypt.
Args:
password: Plain text password to hash
Returns:
Hashed password as a string
"""
salt = bcrypt.gensalt()
hashed: bytes = bcrypt.hashpw(password.encode("utf-8"), salt)
return hashed.decode("utf-8")
def verify_password(password: str, hashed_password: str) -> bool:
"""Verify a password against a hashed password.