Answer the question
In order to leave comments, you need to log in
Why is bcrypt in node so slow?
There is such a code
const bcrypt = require('bcrypt-nodejs');
async encodePassword(password) {
let st = Date.now();
const a = await bcrypt.hashSync(password, bcrypt.genSaltSync(1));
console.log('hash-' + (Date.now() - st));
return a;
}
Answer the question
In order to leave comments, you need to log in
Why are you using it synchronously? Use asynchronously hash
instead hashSync
In general, I use standard crypto
const crypto = require('crypto');
const util = require('util');
const cryptoPbkdf2 = util.promisify(crypto.pbkdf2);
let hashLength = 16;
let iterations = 10;
async function createSaltHash(email) {
let salt = crypto.randomBytes(hashLength).toString('base64');
let hash = (await cryptoPbkdf2(email, salt, iterations, hashLength, 'sha512')).toString();
return { salt, hash }
};
async function checkSaltHash(email, salt, hash) {
if (!email || !hash || !salt) return false;
let userHash = (await cryptoPbkdf2(email, salt, iterations, hashLength, 'sha512')).toString();
let check = userHash == hash;
return check;
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question