2014-08-12 21:41:23 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
2017-05-27 01:44:26 -04:00
|
|
|
var path = require('path');
|
2014-08-12 21:41:23 -04:00
|
|
|
|
2017-10-09 09:40:36 -06:00
|
|
|
var fork = require('./meta/debugFork');
|
2017-06-01 14:04:23 -06:00
|
|
|
|
2017-05-27 01:44:26 -04:00
|
|
|
exports.hash = function (rounds, password, callback) {
|
|
|
|
|
forkChild({ type: 'hash', rounds: rounds, password: password }, callback);
|
|
|
|
|
};
|
2014-11-18 22:55:44 -05:00
|
|
|
|
2017-05-27 01:44:26 -04:00
|
|
|
exports.compare = function (password, hash, callback) {
|
|
|
|
|
if (!hash || !password) {
|
|
|
|
|
return setImmediate(callback, null, false);
|
|
|
|
|
}
|
|
|
|
|
forkChild({ type: 'compare', password: password, hash: hash }, callback);
|
|
|
|
|
};
|
2014-10-07 19:49:18 -04:00
|
|
|
|
2017-05-27 01:44:26 -04:00
|
|
|
function forkChild(message, callback) {
|
2017-10-09 09:40:36 -06:00
|
|
|
var child = fork(path.join(__dirname, 'bcrypt'));
|
2014-10-07 19:49:18 -04:00
|
|
|
|
2017-05-27 01:44:26 -04:00
|
|
|
child.on('message', function (msg) {
|
|
|
|
|
if (msg.err) {
|
|
|
|
|
return callback(new Error(msg.err));
|
|
|
|
|
}
|
2014-11-18 22:55:44 -05:00
|
|
|
|
2017-05-27 01:44:26 -04:00
|
|
|
callback(null, msg.result);
|
|
|
|
|
});
|
2014-08-12 21:41:23 -04:00
|
|
|
|
2017-05-27 01:44:26 -04:00
|
|
|
child.send(message);
|
|
|
|
|
}
|