Ejemplo 1: cómo hacer hash de la contraseña en el nodo js
npm i bcrypt
const bcrypt = require('bcrypt');
async function hashIt(password){
const salt = await bcrypt.genSalt(6);
const hashed = await bcrypt.hash(password, salt);
}
hashIt(password);
// compare the password user entered with hashed pass.
async function compareIt(password){
const validPassword = await bcrypt.compare(password, hashedPassword);
}
compareIt(password);
Ejemplo 2: html-webpack-plugin npm
npm i --save-dev html-webpack-plugin
Ejemplo 3: npm bcrypt
npm install bcrypt
Ejemplo 4: bcryptjs
npm i bcryptjs
# yarn
yarn add bcryptjs
Ejemplo 5: npm bcrypt
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
});
Ejemplo 6: bcrypt compara hash y contraseña
var bcrypt = dcodeIO.bcrypt;
/** One way, can't decrypt but can compare */
var salt = bcrypt.genSaltSync(10);
/** Encrypt password */
bcrypt.hash('anypassword', salt, (err, res) => {
console.log('hash', res)
hash = res
compare(hash)
});
/** Compare stored password with new encrypted password */
function compare(encrypted) {
bcrypt.compare('aboveusedpassword', encrypted, (err, res) => {
// res == true or res == false
console.log('Compared result', res, hash)
})
}
// If u want do the same with NodeJS use this:
/* var bcrypt = require('bcryptjs') */
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)