1import bcrypt from 'bcryptjs'
2
3export const matchPassword = async (enteredpassword, oldPassword) => {
4 return await bcrypt.compare(enteredpassword, oldPassword)
5}
1// password: the value passed from the password form input
2// hash: the value requested from the database. This is the "encrypted" password
3bcrypt.compare(password, hash).then(validPass => {
4 // validPass returns true or false
5 }.catch(err => console.log('error: ' + err));
1
2 var bcrypt = dcodeIO.bcrypt;
3
4 /** One way, can't decrypt but can compare */
5 var salt = bcrypt.genSaltSync(10);
6
7 /** Encrypt password */
8 bcrypt.hash('anypassword', salt, (err, res) => {
9 console.log('hash', res)
10 hash = res
11 compare(hash)
12 });
13
14 /** Compare stored password with new encrypted password */
15 function compare(encrypted) {
16 bcrypt.compare('aboveusedpassword', encrypted, (err, res) => {
17 // res == true or res == false
18 console.log('Compared result', res, hash)
19 })
20 }
21
22// If u want do the same with NodeJS use this:
23/* var bcrypt = require('bcryptjs') */