diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..f1250e5 --- /dev/null +++ b/.npmignore @@ -0,0 +1,4 @@ +support +test +examples +*.sock diff --git a/History.md b/History.md new file mode 100644 index 0000000..c8aa68f --- /dev/null +++ b/History.md @@ -0,0 +1,5 @@ + +0.0.1 / 2010-01-03 +================== + + * Initial release diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..36a3ed7 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ + +test: + @echo "populate me" + +.PHONY: test \ No newline at end of file diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..57927c1 --- /dev/null +++ b/Readme.md @@ -0,0 +1,29 @@ + +# passhash + + Hash passwords + +## License + +(The MIT License) + +Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca> + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..39a5e99 --- /dev/null +++ b/index.js @@ -0,0 +1,66 @@ + +/** + * Module dependencies. + */ + +var crypto = require('crypto'); + +/** + * Bytesize. + */ + +var len = 128; + +/** + * Iterations. ~300ms + */ + +var iterations = 12000; + +/** + * Set length to `n`. + * + * @param {Number} n + * @api public + */ + +exports.length = function(n){ + len = n; +}; + +/** + * Set iterations to `n`. + * + * @param {Number} n + * @api public + */ + +exports.iterations = function(n){ + iterations = n; +}; + +/** + * Hashes a password with optional `salt`, otherwise + * generate a salt for `pass` and invoke `fn(err, salt, hash)`. + * + * @param {String} password to hash + * @param {String} optional salt + * @param {Function} callback + * @api public + */ + +exports.hash = function (pwd, salt, fn) { + if (3 == arguments.length) { + crypto.pbkdf2(pwd, salt, iterations, len, fn); + } else { + fn = salt; + crypto.randomBytes(len, function(err, salt){ + if (err) return fn(err); + salt = salt.toString('base64'); + crypto.pbkdf2(pwd, salt, iterations, len, function(err, hash){ + if (err) return fn(err); + fn(null, salt, hash); + }); + }); + } +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..332f490 --- /dev/null +++ b/package.json @@ -0,0 +1,9 @@ +{ + "name": "pwd", + "version": "0.0.1", + "description": "Hash and compare password with pbkdf2", + "keywords": ["pass", "auth", "password", "authentication"], + "author": "TJ Holowaychuk ", + "dependencies": {}, + "main": "index" +} \ No newline at end of file