Skip to content
Myr

pass.js

This file

Path

examples/auth/pass.js

48 lines · 957 bytes · JavaScript

Last changed by

docs: visionmedia is now tj on GithubDouglas Christopher Wilsonbefore adoptione9539fc

History of this file

Take it

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

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

line 1why, one step back
1

docs: visionmedia is now tj on GithubDouglas Christopher Wilsonbefore adoptione9539fc

line 2why, one step back
2// check out https://github.com/tj/node-pwd

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 3–48why, one step back
3
4/**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};