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