You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
642 B
JavaScript
31 lines
642 B
JavaScript
'use strict';
|
|
|
|
(function(module) {
|
|
var fork = require('child_process').fork;
|
|
|
|
module.hash = function(rounds, password, callback) {
|
|
forkChild({type: 'hash', rounds: rounds, password: password}, callback);
|
|
};
|
|
|
|
module.compare = function(password, hash, callback) {
|
|
forkChild({type: 'compare', password: password, hash: hash}, callback);
|
|
};
|
|
|
|
function forkChild(message, callback) {
|
|
var child = fork('./bcrypt', {
|
|
silent: true
|
|
});
|
|
|
|
child.on('message', function(msg) {
|
|
if (msg.err) {
|
|
return callback(new Error(msg.err));
|
|
}
|
|
|
|
callback(null, msg.result);
|
|
});
|
|
|
|
child.send(message);
|
|
}
|
|
|
|
return module;
|
|
})(exports); |