compare password in bcrypt code example
Example 1: bcrypt compare
import bcrypt from 'bcryptjs'
export const matchPassword = async (enteredpassword, oldPassword) => {
return await bcrypt.compare(enteredpassword, oldPassword)
}
Example 2: 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)
})
}