In this article, we will share with you how to hashing the password and compare password string with hashing password string help of bcrypt. bcrypt
library provides you with making a password in a hash string and normal string compares with hashing string in node.js applications.
Nodejs provides crypto modules to perform the encryption and hashing of sensitive information such as passwords. The Bcrypt node modules provides an easy way to create and compare hashes.
bcrypt
the module provides both synchronous
and asynchronous
methods for work with any string make hashing and any normal string compare with already hashsing formate. so, it will help lots in our node.js application current password check with already store hashed password in our database.
const bcrypt = require('bcrypt');
bcrypt.hash('Your_password', 10, function(err, hash) {
console.log(hash);
// output will be
// $2b$10$wV1ndcFMmu/6Ue4Tuy2OqeSIEQKrjnYMlBCMOG66nBnWk2TUFGDL.
});
bcrypt.compare('Your_password', '$2b$10$wV1ndcFMmu/6Ue4Tuy2OqeSIEQKrjnYMlBCMOG66nBnWk2TUFGDL.', function(err, res) {
if(res) {
console.log('Your password mached with database hash password');
} else {
console.log('Your password not mached.');
}
});
As you can see, password hashing and normal password string compare with existing hashing string it is very easy to use or check the help of bcrypt
library.
We hope that small tutorials help everyone.
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
How to Set Value of Textarea in jQuery
Use the jQuery val() Method...How to implement Datatable in React with Example
In this tutorial, we are going to learn...How to Check If an Object Property is Undefined in JavaScript
Use the strict equality operator (===)...Force Redirect Website URL http to https in Laravel8
In this article, I will share with you h...How to Get the Value of Selected Option in a Select Box Using jQuery
Use the jQuery :selected Selec...