Files
NodeBB/src/password.js

33 lines
827 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) {
2016-08-26 00:05:35 +03:00
var forkProcessParams = {};
if(global.v8debug || parseInt(process.execArgv.indexOf('--debug'), 10) !== -1) {
forkProcessParams = {execArgv: ['--debug=' + (5859), '--nolazy']};
}
var child = fork('./bcrypt', [], forkProcessParams);
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;
2016-10-13 11:40:10 +02:00
}(exports));