Skip to content

Commit 5e5257c

Browse files
committed
Replace passlib with direct bcrypt usage
1 parent 47fbf57 commit 5e5257c

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ dependencies = [
6060
"Flask>=3.1.1",
6161
"Flask-Login>=0.6.3",
6262
"cryptography>=45.0.5",
63-
"passlib>=1.7.4",
6463
"bcrypt>=4.0.0",
6564
"flask-wtf>=1.2.1",
6665
"flask-limiter>=3.8.0",

src/security.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,36 @@
22
from base64 import b64decode, b64encode
33
from typing import cast
44

5+
import bcrypt
56
from cryptography.fernet import Fernet
67
from dotenv import load_dotenv
7-
from passlib.context import CryptContext
88

99
from logging_config import get_logger
1010

1111
load_dotenv()
1212

1313
logger = get_logger(__name__)
1414

15-
# --- Password Hashing ---
16-
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
17-
1815

1916
def verify_password(plain_password: str, hashed_password: str) -> bool:
20-
"""Verify a plain password against its hash."""
2117
try:
22-
return bool(pwd_context.verify(plain_password, hashed_password))
18+
return bool(
19+
bcrypt.checkpw(
20+
plain_password.encode("utf-8")[:72],
21+
hashed_password.encode("utf-8"),
22+
)
23+
)
2324
except Exception as e:
2425
logger.error("password_verification_error", error=str(e))
2526
return False
2627

2728

2829
def get_password_hash(password: str) -> str:
29-
"""Generate password hash."""
30-
return str(pwd_context.hash(password))
30+
hashed: bytes = bcrypt.hashpw(
31+
password.encode("utf-8")[:72],
32+
bcrypt.gensalt(),
33+
)
34+
return hashed.decode("utf-8")
3135

3236

3337
# --- Per-User Credential Encryption ---

0 commit comments

Comments
 (0)