Giter Site home page Giter Site logo

hashers's Introduction

hashers

All password hashing algorithms for Django implemented in javascript for nodejs projects.

Supported Algorithms

  1. PBKDF2PasswordHasher
  2. PBKDF2SHA1PasswordHasher
  3. BCryptSHA256PasswordHasher
  4. BCryptPasswordHasher
  5. SHA1PasswordHasher
  6. MD5PasswordHasher
  7. UnsaltedSHA1PasswordHasher
  8. UnsaltedMD5PasswordHasher
  9. CryptPasswordHasher

Usage

A simple example just verifying and creating Django compatible passwords:

var hashers = require('node-django-hashers');

var h = new hashers.PBKDF2PasswordHasher();
var hash1 = h.encode("password", h.salt());
console.log(h.verify("password", hash1)); // returns true
console.log(h.verify("wrong_password", hash1)); // returns false

You can also get a hashed password, identify the hashing algorithm, and verify the password. The below example is for PBKDF2PasswordHasher, a similar approach to the above code sample can be used for all the other algorithms.

var hashers = require('node-django-hashers');

// Hashed password from Django
var hash_password = "pbkdf2_sha256$24000$EqklNbs3N4lg$COOpqEopVFNhBr20UOtUIm63RGYnX/0efMcNAEOFo50=";

var hash_name = hashers.identifyHasher(hash_password);
var hash_algorithm = hashers.getHasher(hash_name);
console.log(hash_algorithm.verify("password", hash_password)); // returns true
console.log(hash_algorithm.verify("wrong_password", hash_password)); // returns false

A good practice is to verify if the password is using the default algorithm, and update the password if necessary on the database. Every hashing algorithm has an algorithm name. You can pass it in and check if updates are required:

var hashers = require('node-django-hashers');

var hash_password = "286755fad04869ca523320acce0dc6a4"; // "password" in md5
var mustUpdate = hashers.mustUpdateHashedPassword(hash_password, "pbkdf2_sha256");
// mustUpdate is true since we do not want MD5 hash passwords, pbkdf2_sha256 is the default

var hash_algorithm = hashers.getHasher("pbkdf2_sha256");
// update the users password in the database by re encoding the password here

var hash_password = h.encode("password", h.salt());

Installation

npm install node-django-hashers

hashers's People

Contributors

kalvish21 avatar caipirginka avatar

Watchers

James Cloos avatar  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.