bcrypt.compare function code example

Example 1: bcrypt compare

import bcrypt from 'bcryptjs'

export const matchPassword = async (enteredpassword, oldPassword) => {
  return await bcrypt.compare(enteredpassword, oldPassword)
}

Example 2: npm bcrypt

npm install bcrypt

Example 3: bcrypt compare with hash

// password: the value passed from the password form input
// hash: the value requested from the database. This is the "encrypted" password
bcrypt.compare(password, hash).then(validPass => {
	// validPass returns true or false
    }.catch(err => console.log('error: ' + err));