how to hash password in node js 1

how to hash password in node js

npm i bcrypt

const bcrypt = require('bcrypt');
async function hashIt(password){
  const salt = await bcrypt.genSalt(6);
  const hashed = await bcrypt.hash(password, salt);
}
hashIt(password);
// compare the password user entered with hashed pass.
async function compareIt(password){
  const validPassword = await bcrypt.compare(password, hashedPassword);
}
compareIt(password);

Here is what the above code is Doing:
1. We are using the bcrypt library to generate a salt.
2. We are using the salt to hash the password.
3. We are using the bcrypt library to compare the password with the hashed password.

Similar Posts