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.
nodebb/bcrypt.js

34 lines
662 B
JavaScript

11 years ago
'use strict';
10 years ago
var bcrypt = require('bcryptjs'),
async = require('async');
11 years ago
process.on('message', function(msg) {
if (msg.type === 'hash') {
hashPassword(msg.password, msg.rounds);
} else if (msg.type === 'compare') {
10 years ago
bcrypt.compare(msg.password, msg.hash, done);
}
});
function hashPassword(password, rounds) {
async.waterfall([
function(next) {
bcrypt.genSalt(parseInt(rounds, 10), next);
},
function(salt, next) {
bcrypt.hash(password, salt, next);
}
10 years ago
], done);
}
10 years ago
function done(err, result) {
if (err) {
process.send({err: err.message});
return process.disconnect();
}
process.send({result: result});
process.disconnect();
11 years ago
}