Skip to content

Commit e0f1d9e

Browse files
author
CarlosAndreo
committed
fix: update to use pwdlib with argon2 instead of passlib
1 parent 2240ed7 commit e0f1d9e

6 files changed

Lines changed: 299 additions & 191 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ The mongo-express UI will be available at `http://localhost:8081`.
8686
[license-url]: https://github.com/CarlosAndreo/fastapi-mongodb/blob/main/LICENSE
8787
[python-badge]: https://img.shields.io/badge/Python-3.13.7-blue?style=for-the-badge&logo=python&logoColor=white&labelColor=3776AB
8888
[python-url]: https://www.python.org/downloads/release/python-3137/
89-
[fastapi-badge]: https://img.shields.io/badge/FastAPI-0.117.1-blue?style=for-the-badge&logo=fastapi&logoColor=white&labelColor=009688
89+
[fastapi-badge]: https://img.shields.io/badge/FastAPI-0.118.0-blue?style=for-the-badge&logo=fastapi&logoColor=white&labelColor=009688
9090
[fastapi-url]: https://fastapi.tiangolo.com/
9191
[mongodb-badge]: https://img.shields.io/badge/MongoDB-8.0-green?style=for-the-badge&logo=mongodb&logoColor=white&labelColor=47A248
9292
[mongodb-url]: https://www.mongodb.com/

app/core/security.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
from passlib.context import CryptContext
1+
from pwdlib import PasswordHash
22

3-
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
3+
password_hash = PasswordHash.recommended()
44

55

6-
def hash_password(password: str) -> str:
6+
def get_password_hash(password: str) -> str:
77
"""
88
Hash a password using bcrypt
99
"""
10-
return pwd_context.hash(secret=password)
10+
return password_hash.hash(password=password)
1111

1212

1313
def verify_password(plain_password, hashed_password):
1414
"""
1515
Verify a password against a hashed password
1616
"""
17-
return pwd_context.verify(secret=plain_password, hash=hashed_password)
17+
return password_hash.verify(password=plain_password, hash=hashed_password)

app/services/user.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from core.security import hash_password
1+
from core.security import get_password_hash
22
from repositories.user import find_user_by_username, insert_user, update_user
33
from schemas.user import User, UserCreate, UserInDB
44

@@ -22,7 +22,7 @@ async def create_user(user: UserCreate) -> User | None:
2222
"""
2323
Create user in the database
2424
"""
25-
hashed_password = hash_password(password=user.password)
25+
hashed_password = get_password_hash(password=user.password)
2626
user_in_db = UserInDB(
2727
**user.model_dump(exclude={"password"}), hashed_password=hashed_password
2828
)
@@ -34,7 +34,7 @@ async def change_password(user: User, new_password: str) -> User | None:
3434
"""
3535
Change user password
3636
"""
37-
hashed_password = hash_password(password=new_password)
37+
hashed_password = get_password_hash(password=new_password)
3838
user_in_db = UserInDB(
3939
**user.model_dump(exclude={"password"}), hashed_password=hashed_password
4040
)

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
services:
22

33
mongodb:
4-
image: mongo:8.0.13-noble
4+
image: mongo:8.0.14-noble
55
container_name: ${MONGO_INITDB_DATABASE}
66
restart: always
77
ports:

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ authors = [{ name = "Carlos Andreo", email = "[email protected]" }]
99

1010
[dependency-groups]
1111
prod = [
12-
"fastapi[standard]==0.117.1",
12+
"fastapi[standard]==0.118.0",
1313
"motor==3.7.1",
14-
"passlib[bcrypt]==1.7.4",
14+
"pwdlib[argon2]==0.2.1",
1515
"pydantic-settings==2.11.0",
1616
"pyjwt==2.10.1",
1717
]
1818
lint = [
19-
"ruff==0.13.1",
19+
"ruff==0.13.2",
2020
]
2121

2222
[tool.uv]

0 commit comments

Comments
 (0)