Hashing passwords via FastAPI
Last updated
Last updated
The FastAPI documentation already has a good article on this topic:
First thing we have to do is install passlib
to usebcrypt
We will have to import the CryptContext
and tell passlib
what is the default hashing algorithm
We also have to update the operation path
Before creating the user, we are getting the password hashed via pwd_context.hash
After which we are replacing user.password
in the schema with the hashed password
As this is updated it should store the hashed password in the database
We will call this file utils.py
In this file we can import all the logic and define a function to hash our password
The thing that changes in our main.py
file is the import and the variable passed in the operation path