From the course: Node: Authentication
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Hashing and validating passwords with bcrypt
From the course: Node: Authentication
Hashing and validating passwords with bcrypt
- Mongoose models provide so-called pre-save hooks that we can use to make sure that passwords are always hashed as soon as they're saved to the database. If you like to use any other database, the provided functionality of the database may differ, but the actual hashing should work similar. So to create such a pre-save hook I now head into Server, Models, and then into User Model. The first thing I have to do is I have to install bcrypt. So I'm stopping the Node.js process now with Ctrl C, and then I'll run npm install-S bcrypt. Next we of course have to require bcrypt in our model file. So add const bcrypt = require bcrypt and now we are ready to implement this pre-save hook for that scroll down somewhere of the line 44. First I will create a helper that will do the actual password hashing. Bcrypt today offers a promise based interface, a callback based interface, and also a synchronous one. Using callbacks or promises…
Contents
-
-
-
-
(Locked)
Registering new users13m 54s
-
(Locked)
Why plaintext passwords are bad3m 28s
-
(Locked)
Hashing and validating passwords with bcrypt7m 27s
-
(Locked)
Implementing login and logout10m 22s
-
(Locked)
Deserializing the logged in user from the database4m 49s
-
(Locked)
Offer remember me7m 13s
-
(Locked)
Require user verification10m 24s
-
(Locked)
Resetting passwords4m 1s
-
(Locked)
Implementing the password reset flow14m 1s
-
(Locked)
-
-
-