bcrypt compare hash and password 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)
})
}
Example 3: bcrypt compare with hash
bcrypt.compare(password, hash).then(validPass => {
}.catch(err => console.log('error: ' + err));