shorter bcrypt

v1.18.x
Barış Soner Uşaklı 10 years ago
parent 406126536a
commit 56ed6d2112

@ -9,11 +9,10 @@ process.on('message', function(msg) {
if (msg.type === 'hash') {
hashPassword(msg.password, msg.rounds);
} else if (msg.type === 'compare') {
compare(msg.password, msg.hash);
bcrypt.compare(msg.password, msg.hash, done);
}
});
function hashPassword(password, rounds) {
async.waterfall([
function(next) {
@ -22,23 +21,14 @@ function hashPassword(password, rounds) {
function(salt, next) {
bcrypt.hash(password, salt, next);
}
], function(err, hash) {
if (err) {
process.send({err: err.message});
return process.disconnect();
}
process.send({result: hash});
process.disconnect();
});
], done);
}
function compare(password, hash) {
bcrypt.compare(password, hash, function(err, res) {
if (err) {
process.send({err: err.message});
return process.disconnect();
}
process.send({result: res});
process.disconnect();
});
function done(err, result) {
if (err) {
process.send({err: err.message});
return process.disconnect();
}
process.send({result: result});
process.disconnect();
}
Loading…
Cancel
Save