how compare two passwords bcrypt hashes code example
Example 1: 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 2: bcrypt compare with hash
bcrypt.compare(password, hash).then(validPass => {
}.catch(err => console.log('error: ' + err));