Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

Commit

Permalink
added readme
Browse files Browse the repository at this point in the history
  • Loading branch information
kbjr committed Jun 20, 2011
1 parent f625c80 commit e4fdd04
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/sechash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
51 changes: 51 additions & 0 deletions readme.textile
Original file line number Diff line number Diff line change
@@ -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.