|
|
|
@ -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) {
|
|
|
|
|
function done(err, result) {
|
|
|
|
|
if (err) {
|
|
|
|
|
process.send({err: err.message});
|
|
|
|
|
return process.disconnect();
|
|
|
|
|
}
|
|
|
|
|
process.send({result: res});
|
|
|
|
|
process.send({result: result});
|
|
|
|
|
process.disconnect();
|
|
|
|
|
});
|
|
|
|
|
}
|