Lesson 23. Building a user login and hashing passwords

 

In lesson 22, you added flash messages to your controller actions and views. In this lesson, you dive deeper into the User model by creating a sign-up and login form. Then you add a layer of security to your application by hashing users’ passwords and saving your users’ login state. Next, you add some more validations at the controller level with the help of the express-validator package. By the end of this lesson, a user should be able to create an account, have their password saved securely in your database, and log in or log out as they like.

This lesson covers

  • Creating a user log-in form
  • Hashing data in your database with bcrypt
Consider this

You deliver a prototype of your recipe application in which users can create accounts and store their unencrypted passwords in your database. You’re reasonably concerned that your database might get hacked or (even more embarrassing) that you might show user passwords in plain text to all users. Luckily, security is a big concern in the programming world, and tools and security techniques are available to protect sensitive data from being exposed. bcrypt is one such tool you’ll use to mask passwords in your database so that they can’t be hacked easily in the future.

23.1. Implementing the user login form

Before you dive into the logic that will handle users logging into the recipe application, establish what their sign-up and login forms will look like.

23.2. Hashing passwords

23.3. Adding validation middleware with express-validator

Summary

sitemap