Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 498dc6b0f7e3ee092e22eac2b2bed37a06f4d6c5 0 parents
@tj authored
4 .npmignore
@@ -0,0 +1,4 @@
+support
+test
+examples
+*.sock
5 History.md
@@ -0,0 +1,5 @@
+
+0.0.1 / 2010-01-03
+==================
+
+ * Initial release
5 Makefile
@@ -0,0 +1,5 @@
+
+test:
+ @echo "populate me"
+
+.PHONY: test
29 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.
66 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);
+ });
+ });
+ }
+};
9 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 <tj@vision-media.ca>",
+ "dependencies": {},
+ "main": "index"
+}
Please sign in to comment.
Something went wrong with that request. Please try again.