Files
NodeBB/src/password.js

32 lines
753 B
JavaScript
Raw Normal View History

2014-08-12 21:41:23 -04:00
'use strict';
2017-05-27 01:44:26 -04:00
var fork = require('child_process').fork;
var path = require('path');
2014-08-12 21:41:23 -04:00
2017-06-01 14:04:23 -06:00
var debugParams = require('./meta/debugParams');
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-06-01 14:04:23 -06:00
var child = fork(path.join(__dirname, 'bcrypt'), [], debugParams());
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);
}