User Authentication Using b-crypt
Abbreviations
*[npm]: Node Package Manager
Introduction
In this tutorial we are going to build a secure Node.js user authentication system. I will be covering all of the security concerns that you will run into while building an authentication system. We will also cover how to securely store a password in case of a database breach. Lastly, we will cover how to login a user securely based on their name and password.
What is password salt
allows multiple users to have the same password but when stored they look different from each other
Ex without salt:
Ex with salt:
the bcrypt library takes care of all this for us
bcrypt is an async library
How to properly hash a password
Technique 1
(generate a salt and hash on separate function calls)
Technique 2
(auto-gen a salt and hash)
User login
compare method gets the salt out of the hashed password, uses it on the plain test password and then compares it to see if they match
compare method also protects against timing attacks
Steps
make project folder and cd into it
initialize npm
this will set up the initial project structure and create package.json
install required dependencies
install
nodemon
as a developer dependencyanytime a change is made to a file, it will automatically refresh the server instead of manually having to do it
go into
package.json
and create the scriptdevServer
to startnodemon
you do not have to call it
deServer
, you can call it whatever you want
create server.js
this will be the main server in node.js
start up the server (see server.js for steps)