Browse files

added readme

  • Loading branch information...
1 parent f625c80 commit e4fdd04fc786e4d93dd3b4207df81af7ccb7c36f @kbjr committed Jun 20, 2011
Showing with 54 additions and 4 deletions.
  1. +3 −4 lib/sechash.js
  2. +51 −0 readme.textile
View
7 lib/sechash.js
@@ -31,17 +31,16 @@ module.exports = (function() {
* Hash a string with salt and key stretching
*
* @access public
+ * @param string the hashing algorithm
* @param string the string to hash
* @param string the salt value
* @param number the number of hash iterations
- * @param string the hashing algorithm
* @return string
*/
- self.strongHash = function(str, salt, algorithm, iterations) {
+ self.strongHash = function(algorithm, str, salt, iterations) {
// Default the optional arguments
- algorithm = algorithm || 'md5';
if (salt == null) {
- salt = hash('md5', String(Math.random())).substring(0, 3);
+ salt = hash(algorithm, String(Math.random())).substring(0, 3);
}
if (iterations == null) {
iterations = Math.round(Math.random() * 9000) + 1000;
View
51 readme.textile
@@ -0,0 +1,51 @@
+h1. sechash
+
+h4. Secure password hashing with salt and key stretching
+
+Author: James Brumond
+Version: 0.1.0
+
+Copyright 2011 James Brumond
+Dual licensed under MIT and GPL
+
+h2. Install
+
+<pre><code>npm install sechash</code></pre>
+
+h2. Usage
+
+h3. Running a simple hash
+
+<pre><code>var sechash = require('sechash');
+
+// This will do a simple md5 hash, the same as if you used the
+// built-in "crypto" module.
+var hash = sechash.simpleHash('md5', 'Your String');</code></pre>
+
+h3. Using the strong stuff
+
+<pre><code>var sechash = require('sechash');
+
+// This will hash the string quite a bit more strongly. It adds
+// a salt parameter and an iterations parameter to make the hash
+// harder to break.
+var hash1 = sechash.strongHash('md5', 'Your String', 'Salt', 2500);
+
+// If no salt value is given, it will randomly generate salt for
+// you; similarly, if no iteration count is given, it will randomly
+// select a number between 1000 and 10000.
+var hash2 = sechash.strongHash('md5', 'Your String');</code></pre>
+
+h3. Testing a hash
+
+<pre><code>var sechash = require('sechash');
+
+// First we generate a hash...
+var hash = sechash.strongHash('md5', 'Your String', 'Salt', 2500);
+
+// To test if a string matches a hash, we you the testHash method
+sechash.testHash('Your String', hash); // true
+sechash.testHash('Another String', hash); // false
+
+</code></pre>
+

0 comments on commit e4fdd04

Please sign in to comment.