Coder Social home page Coder Social logo

pbkdf2-password's Introduction

pbkdf2-password Build Status

Easy salt/password creation for Node.js, extracted from Mosca.

Installation

You can install pbkdf2-password via npm or yarn.

Using npm

npm install pbkdf2-password

Using Yarn

yarn add pbkdf2-password

Usage

var bkfd2Password = require("pbkdf2-password");
var hasher = bkfd2Password();
var assert = require("assert");
var opts = {
  password: "helloworld"
};

hasher(opts, function(err, pass, salt, hash) {
  opts.salt = salt;
  hasher(opts, function(err, pass, salt, hash2) {
    assert.deepEqual(hash2, hash);

    // password mismatch
    opts.password = "aaa";
    hasher(opts, function(err, pass, salt, hash2) {
      assert.notDeepEqual(hash2, hash);
      console.log("OK");
    });
  });
});

API

### bkfd2Password(options)

Creates a new hasher functions, with the specified options.

Options:

  • saltLength, the length of the random salt
  • iterations, number of pbkdf2 iterations
  • keyLength, the length of the generated keys
  • digest, the digest algorithm, default 'sha1'
### hasher(opts, function(err, pass, salt, hash))

Hash a password, using a hash and the pbkd2 crypto module.

Options:

  • password, the password to hash.
  • salt, the salt to use, as a base64 string.

If the password is left undefined, a new 10-bytes password will be generated, and converted to base64.

If the salt is left undefined, a new salt is generated.

The callback will be called with the following arguments:

  • the error, if something when wrong.
  • the password.
  • the salt, encoded in base64.
  • the hash, encoded in base64.

MIT

pbkdf2-password's People

Contributors

mcollina avatar emmo00 avatar

Stargazers

Henrique Silvério avatar Sandaru Fernando avatar Savino Basanisi avatar  avatar Jeon Hyeong Lee avatar Shiyi Lyu avatar  avatar Maxim Golitsyn avatar Jiabin Peng avatar Shiyi Lyu 002 avatar  avatar Akash Sawant avatar 巴拉巴拉小魔仙 avatar Markus Lerner avatar Marcel Körtgen avatar JooHyung Kim avatar 62tae avatar Hemerson Vianna avatar Jimmy Moon avatar Ken avatar Yosh avatar Bent Cardan avatar  avatar dap avatar

Watchers

 avatar James Cloos avatar Matteo Murgida avatar baaxl9vh avatar  avatar

pbkdf2-password's Issues

Error on hasing password.

Hi, so I'm using this in a typescript enviorment and I get one error:
crypto.randomBytes is not a function

I don't know why it's that, here is what I've done:

import * as pbkdf2Password from 'pbkdf2-password';

const hasher = pbkdf2Password();

hash ( password: Object/string ): string {
      return hasher(password, (err, pass, salt, hash) => salt);
  }

And then I tried:

hash( passwordAsString )
hash(passowrdAsObjectLiteral) // with password key: value

and it's the same. Any ideas what I'm doing wrong?

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.