Skip to content

Instantly share code, notes, and snippets.

@BarronKane
Created February 17, 2016 05:00
Show Gist options
  • Select an option

  • Save BarronKane/ff813214bbdbfb715ab5 to your computer and use it in GitHub Desktop.

Select an option

Save BarronKane/ff813214bbdbfb715ab5 to your computer and use it in GitHub Desktop.

Revisions

  1. Lance created this gist Feb 17, 2016.
    19 changes: 19 additions & 0 deletions crypto
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    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);
    });
    });
    });