Hashing of password is the common approach to secure our authentication, So today we will learn how we can hash password in Node.js with Bcrypt.
Hashing of Password in Node.js
Introduction - Hashing of Password
Hashing Library
npm i bcrypt
Usage
const bcrypt = require('bcrypt');
Hashing the password
const myFunction = async () => { const password = 'myPassword';
const hashingPassword =
await bcrypt.hash(password , 9);
}
Now, you can store the hashingPassword into the database.
[Meanings of underlined words in the above code]
1. Password is the user password
2. Here you can select any number if you want, but 9 is the perfect number to encrypt the password. If you select a small number than 9 then it will be crackable or if you choose a number which is bigger than 9, it will take time to render.
Verify the password
const isMatch = bcrypt.compare ( 'myPassword' , hashedPassword
);
// 'myPassword' is the user password.// hashedPassword is the hashed password from the database.
if (isMatch){ console.log('Logged in');
} else { console.log('Incorrect Password');
}
Learn more on Hashing of Password in Node.js
Conclusion
Reference / Source - Poor Coders
hashing password php, password hashing and salting, hashing password in java, what is hashing encryption, what are the advantages of hashing passwords, password hashing competition, what is password hashing and salting, how password hashing works, what is difference between encryption and hashing, hashing the password, java password hashing library, can hashed passwords be decrypted, password hashing best practices, password hashing php 7, password hashing digest, hashing password in login, hashing password sha, how safe is hashing password, hashing password access, password hashing example bcrypt, password hashing definition, hashing password android studio, hashing password compare, hashing password javascript, password hashing javascript library, hashing password scrypt, hashing password jpa, hashing password yii2, best password hashing 2020, hash password example, hashed password to plain text, what is password hashing, how to get hash password, password hasher, hash password converter to text online