all files / src/ password.js

92.86% Statements 13/14
50% Branches 1/2
100% Functions 5/5
92.86% Lines 13/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31                                   
'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) {
			Iif (msg.err) {
				return callback(new Error(msg.err));
			}
 
			callback(null, msg.result);
		});
 
		child.send(message);
	}
 
	return module;
})(exports);