Skip to content

Instantly share code, notes, and snippets.

@BarronKane
Created February 17, 2016 05:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BarronKane/ff813214bbdbfb715ab5 to your computer and use it in GitHub Desktop.
Save BarronKane/ff813214bbdbfb715ab5 to your computer and use it in GitHub Desktop.
app.post('/', function (req, res) {
if (!req.body.user || !req.body.pass) {
res.send('Username and password both required');
return;
}
crypto.randomBytes(128, function (err, salt) {
if (err) { throw err; }
salt = new Buffer(salt).toString('hex');
crypto.pbkdf2(req.body.pass, salt, 7000, 256,
function (err, hash) {
if (err) { throw err; }
userStore[req.body.user] = {salt : salt,
hash : (new Buffer(hash).toString('hex')) };
res.send('Thanks for registering ' + req.body.user);
console.log(userStore);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment