Description
User passwords are currently not stored at all. Add a hashed_password field and hash passwords on creation using passlib.
What to do
Acceptance Criteria
POST /users/ accepts a password field
- The stored value in the database is a bcrypt hash, not the plain text password
GET /users/ and GET /users/{id} do not return hashed_password
- The
/docs UI shows password as a required field on user creation
Hints
from passlib.context import CryptContext
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
hashed = pwd_context.hash("mypassword")
Difficulty
🟡 Intermediate
Description
User passwords are currently not stored at all. Add a
hashed_passwordfield and hash passwords on creation usingpasslib.What to do
pip install passlib[bcrypt]to the project dependencies (updatepyproject.tomlorrequirements.txt)hashed_password: strcolumn to theUsermodel inmodels.pypassword: strtoUserCreateschema (the raw password coming in)hashed_passwordinUserResponse— it must not be returned by any endpointcrud.py, hash the password before saving:pwd_context.hash(user.password)auth.pyutility file with theCryptContextsetupAcceptance Criteria
POST /users/accepts apasswordfieldGET /users/andGET /users/{id}do not returnhashed_password/docsUI showspasswordas a required field on user creationHints
Difficulty
🟡 Intermediate