Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jun 27, 2012
0 parents commit 498dc6b
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .npmignore
@@ -0,0 +1,4 @@
support
test
examples
*.sock
5 changes: 5 additions & 0 deletions History.md
@@ -0,0 +1,5 @@

0.0.1 / 2010-01-03
==================

* Initial release
5 changes: 5 additions & 0 deletions Makefile
@@ -0,0 +1,5 @@

test:
@echo "populate me"

.PHONY: test
29 changes: 29 additions & 0 deletions 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 changes: 66 additions & 0 deletions 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 changes: 9 additions & 0 deletions 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"
}

0 comments on commit 498dc6b

Please sign in to comment.