use bcrypt in nodejs code example
Example 1: npm bcrypt
npm install bcrypt
Example 2: bcryptjs
npm i bcryptjs
# yarn
yarn add bcryptjs
Example 3: bcrypt compare hash and password
var bcrypt = dcodeIO.bcrypt;
var salt = bcrypt.genSaltSync(10);
bcrypt.hash('anypassword', salt, (err, res) => {
console.log('hash', res)
hash = res
compare(hash)
});
function compare(encrypted) {
bcrypt.compare('aboveusedpassword', encrypted, (err, res) => {
console.log('Compared result', res, hash)
})
}
Example 4: bcrypt always return faslse in node js
first thing make sure to increase the length(must be greater than 60/70) in database and then checkout