xxxxxxxxxx
const bcrypt = require('bcrypt');
// Plain text password to be hashed
const plainPassword = 'myPassword123';
// Generate a salt
const saltRounds = 10;
const salt = bcrypt.genSaltSync(saltRounds);
// Hash the password using the generated salt
const hashedPassword = bcrypt.hashSync(plainPassword, salt);
console.log('Password:', plainPassword);
console.log('Hashed Password:', hashedPassword);
// Comparing a password with the hashed password
const isPasswordMatch = bcrypt.compareSync(plainPassword, hashedPassword);
console.log('Is Password Match:', isPasswordMatch);
xxxxxxxxxx
const bcrypt = require('bcrypt');
const saltRounds = 10;
bcrypt.hash(myPlaintextPassword, saltRounds, function(err, hash) {
// Store hash in your password DB.
});
// Load hash from your password DB.
bcrypt.compare(myPlaintextPassword, hash, function(err, result) {
// result == true
});
xxxxxxxxxx
var bcrypt = require('bcryptjs');
var salt = bcrypt.genSaltSync(10);
var hash = bcrypt.hashSync("B4c0/\/", salt);
// Store hash in your password DB.
xxxxxxxxxx
const bcrypt = require('bcrypt');
// To hash user password (Sync)
let salt = bcrypt.genSaltSync(10)
hashPassword = bcrypt.hashSync(data.password, salt)
// To compare password with hashed password
// Load hash from your password DB.
bcrypt.compareSync(myPlaintextPassword, hash); // true
xxxxxxxxxx
// Load hash from your password DB.
bcrypt.compareSync("B4c0/\/", hash); // true
bcrypt.compareSync("not_bacon", hash); // false