Skip to content

Commit f07ecfc

Browse files
committed
feat: enhance security with bcrypt for password hashing and verification; add get_table method to Data API client; increase video description length limit
1 parent 835b9e2 commit f07ecfc

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

app/core/security.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
from datetime import datetime, timedelta, timezone
22
from typing import Union, Optional, List, Any
33

4-
from passlib.context import CryptContext
4+
import bcrypt
55
from jose import jwt
66
from pydantic import BaseModel
77

88
from app.core.config import settings
99

10-
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
11-
1210

1311
class TokenPayload(BaseModel):
1412
sub: Optional[Union[str, Any]] = None
@@ -17,11 +15,13 @@ class TokenPayload(BaseModel):
1715

1816

1917
def verify_password(plain_password: str, hashed_password: str) -> bool:
20-
return pwd_context.verify(plain_password, hashed_password)
18+
password_bytes = plain_password.encode("utf-8")[:72]
19+
return bcrypt.checkpw(password_bytes, hashed_password.encode("utf-8"))
2120

2221

2322
def get_password_hash(password: str) -> str:
24-
return pwd_context.hash(password)
23+
password_bytes = password.encode("utf-8")[:72]
24+
return bcrypt.hashpw(password_bytes, bcrypt.gensalt()).decode("utf-8")
2525

2626

2727
def create_access_token(

app/db/astra_client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ def __init__(self, *, api_endpoint: str, token: str, namespace: str):
8585
def collection(self, table_name: str): # type: ignore
8686
return self._db.get_collection(table_name)
8787

88+
def get_table(self, table_name: str): # type: ignore
89+
"""Get a table (for working with CQL tables via Data API)."""
90+
return self._db.get_table(table_name)
91+
8892
async def create_collection(self, name: str, **kwargs): # noqa: D401
8993
"""Proxy to the underlying AsyncDatabase.create_collection."""
9094
return await self._db.create_collection(name, **kwargs)

app/models/video.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class VideoBase(BaseModel):
4242
model_config = ConfigDict(populate_by_name=True)
4343

4444
name: str = Field(..., min_length=3, max_length=100, alias="title")
45-
description: Optional[str] = Field(default=None, max_length=1000)
45+
description: Optional[str] = Field(default=None, max_length=2000)
4646
tags: List[str] = Field(default_factory=list)
4747

4848

@@ -108,7 +108,7 @@ class VideoUpdateRequest(BaseModel):
108108
name: Optional[str] = Field(
109109
default=None, min_length=3, max_length=100, alias="title"
110110
)
111-
description: Optional[str] = Field(default=None, max_length=1000)
111+
description: Optional[str] = Field(default=None, max_length=2000)
112112
tags: Optional[List[str]] = None
113113

114114

0 commit comments

Comments
 (0)