pass.js
This file
Path
examples/auth/pass.js
48 lines · 1013 bytes · JavaScript
Last changed by
Merge pull request #1571 from jlubawy/masterTJ Holowaychukbefore adoption49cc1a7
History of this fileTake it
The walk stopped after 200 commits: lines older than 496ee40 point at it.
Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption496ee40
lines 1–33why, one step back12// check out https://github.com/visionmedia/node-pwd34/**5 * Module dependencies.6 */78var crypto = require('crypto');910/**11 * Bytesize.12 */1314var len = 128;1516/**17 * Iterations. ~300ms18 */1920var iterations = 12000;2122/**23 * Hashes a password with optional `salt`, otherwise24 * generate a salt for `pass` and invoke `fn(err, salt, hash)`.25 *26 * @param {String} password to hash27 * @param {String} optional salt28 * @param {Function} callback29 * @api public30 */3132exports.hash = function (pwd, salt, fn) {33 if (3 == arguments.length) {Merge pull request #1571 from jlubawy/masterTJ Holowaychukbefore adoption49cc1a7
lines 34–36why, one step back34 crypto.pbkdf2(pwd, salt, iterations, len, function(err, hash){35 fn(err, (new Buffer(hash, 'binary')).toString('base64'));36 });Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption496ee40
lines 37–43why, one step back37 } else {38 fn = salt;39 crypto.randomBytes(len, function(err, salt){40 if (err) return fn(err);41 salt = salt.toString('base64');42 crypto.pbkdf2(pwd, salt, iterations, len, function(err, hash){43 if (err) return fn(err);Merge pull request #1571 from jlubawy/masterTJ Holowaychukbefore adoption49cc1a7
line 44why, one step back44 fn(null, salt, (new Buffer(hash, 'binary')).toString('base64'));Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption496ee40
lines 45–48why, one step back45 });46 });47 }48};