Skip to content
Myr

pass.js

This file

Path

examples/auth/pass.js

48 lines · 966 bytes · JavaScript

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than f41d09a point at it.

remove app.router and refactor middleware processingRoman Shtylmanbefore adoptionf41d09a

lines 1–48why, one step back
1
2// 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) {34 crypto.pbkdf2(pwd, salt, iterations, len, function(err, hash){35 fn(err, hash.toString('base64'));36 });37 } 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);44 fn(null, salt, hash.toString('base64'));45 });46 });47 }48};