Files
NodeBB/src/password.js

31 lines
642 B
JavaScript
Raw Normal View History

2014-08-12 21:41:23 -04:00
'use strict';
(function(module) {
2014-10-07 19:49:18 -04:00
var fork = require('child_process').fork;
2014-08-12 21:41:23 -04:00
module.hash = function(rounds, password, callback) {
2014-11-18 22:55:44 -05:00
forkChild({type: 'hash', rounds: rounds, password: password}, callback);
2014-08-12 21:41:23 -04:00
};
module.compare = function(password, hash, callback) {
2014-11-18 22:55:44 -05:00
forkChild({type: 'compare', password: password, hash: hash}, callback);
};
function forkChild(message, callback) {
var child = fork('./bcrypt', {
2014-10-07 19:49:18 -04:00
silent: true
2014-11-18 22:55:44 -05:00
});
2014-10-07 19:49:18 -04:00
2014-11-18 22:55:44 -05:00
child.on('message', function(msg) {
if (msg.err) {
return callback(new Error(msg.err));
}
2014-10-07 19:49:18 -04:00
2014-11-18 22:55:44 -05:00
callback(null, msg.result);
2014-10-07 19:49:18 -04:00
});
2014-11-18 22:55:44 -05:00
child.send(message);
}
2014-08-12 21:41:23 -04:00
2014-10-07 19:49:18 -04:00
return module;
})(exports);