Coder Social home page Coder Social logo

password-slow-hash's Introduction

password-slow-hash

Note scrypt is more secure than this module as it increases memory and processor usage.

Linux Build

Node password hashing, salting and validating methods. An async tool using nodes inbuilt crypto library, pbkdf2.

Installation

$ npm install password-slow-hash

Example

var password = require('password-slow-hash');

password.hash('myCrazyPassword!', function(err, generatedHash){
	if(err) {
		throw err;
	} else {
		// save generatedHash to users password field in db
	}	
});

password.validate('myCrazyPassword!', usersSavedHash, function(err, isValid){
	if(err) {
		throw err;
	} else if(isValid){
		// you are authenticated
	} else {
		//you are not authenticated
	}
});

Features

  • Utilises nodes inbuilt pbkdf2 functionality for slowing down hash generation
  • Cryptographically random salting
  • Slow equals password validation

Defaults

  • algorithm: 'sha256'
  • saltByteSize: 32
  • hashByteSize: 32
  • pbkdf2 iterations: 25000
  • returnType: 'string'

Iterations

One of the most important settings is iterations. This determines how long the hash algorithm will take to create the hash. The longer time needed to create the hash the longer it will take to crack the passwords. This number should be optimised on your system so the hash generation takes the longest time you and your users can tolerate. It should be increased as cpu speeds increase to keep your passwords safe.

Options

One or more of the above defaults can be overridden in an options object sent to the hash function if specific control of the hashing algorithm is required.

var options = {
	algorithm: 'sha512',
	saltByteSize: 64,
	hashByteSize: 64,
	iterations: 35000,
	returnType: 'object'
};

password.hash('my|Cr4zy$PÅssword!', options, function(err, generatedHash){
	if(err) {
		throw err;
	} else {
		// save generatedHash to users password field in db
	}	
});

Tests

To run the test suite, first install the dependencies, then run npm test:

$ npm install
$ npm test

License

MIT

password-slow-hash's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.