Giter VIP home page Giter VIP logo

password-sheriff's Introduction

Password Sheriff

FOSSA Status

Node.js (and browserify supported) library to enforce password policies.

Install

npm install password-sheriff

Usage

var PasswordPolicy = require('password-sheriff').PasswordPolicy;

// Create a length password policy
var lengthPolicy = new PasswordPolicy({length: {minLength: 6}});

// will throw as the password does not meet criteria
lengthPolicy.assert('hello');

// returns false if password does not meet rules
assert.equal(false, lengthPolicy.check('hello'));

// explains the policy
var explained = lengthPolicy.explain();

assert.equal(1, explained.length);

// easier i18n
assert.equal('lengthAtLeast', explained[0].code);
assert.equal('At least 6 characters in length',
             format(explained[0].message, explained[0].format));

API

Password Rules

Password Rules are objects that implement the following methods:

  • rule.validate(options): method called after the rule was created in order to validate options arguments.
  • rule.assert(options, password): returns true if password is valid.
  • rule.explain(options): returns an object with code, message and format attributes:
    • code: Identifier of the rule. This attribute is meant to aid i18n.
    • message: Description of the rule that must be formatted using util.format.
    • format: Array of string or Number that will be used for the replacements required in message.
  • rule.missing(options, password): returns an object similar to rule.explain plus an additional field verified that informs whether the password meets the rule.

Example of rule.explain method:

FooRule.prototype.explain = function (options) {
  return {
    // identifier rule (to make i18n easier)
    code: 'foo',
    message: 'Foo should be present at least %d times.',
    format: [options.count]
  };
};

When explained:

var explained = fooRule.explain({count: 5});

// "Foo should be present at least 5 times"
util.format(explained.message, explained.format[0]);

See the custom-rule example section for more information.

Built-in Password Rules

Password Sheriff includes some default rules:

  • length: The minimum amount of characters a password must have.
var lengthPolicy = new PasswordPolicy({length: {minLength: 3}});
  • contains: Password should contain all of the charsets specified. There are 4 predefined charsets: upperCase, lowerCase, numbers and specialCharacters (specialCharactersare the ones defined in OWASP Password Policy recommendation document).
var charsets = require('password-sheriff').charsets;

var containsPolicy = new PasswordPolicy({contains: {
  expressions: [charsets.upperCase, charsets.numbers]
}});
  • containsAtLeast: Passwords should contain at least atLeast of a total of expressions.length groups.
var charsets = require('password-sheriff').charsets;

var containsAtLeastPolicy = new PasswordPolicy({
  containsAtLeast: {
    atLeast: 2,
    expressions: [ charsets.lowerCase, charsets.upperCase, charsets.numbers ]
  }
});
  • identicalChars: Passwords should not contain any character repeated continuously max + 1 times.
var identitcalCharsPolicy = new PasswordPolicy({
  identicalChars: {
    max: 3
  }
});

See the default-rules example section for more information.

Issue Reporting

If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.

Author

Auth0

License

This project is licensed under the MIT license. See the LICENSE file for more info.

FOSSA Status

password-sheriff's People

Contributors

charmedsatyr avatar damieng avatar davidpatrick avatar dependabot[bot] avatar evansims avatar fossabot avatar frederikprijck avatar glena avatar hzalaz avatar jimmyjames avatar joshcanhelp avatar knupman avatar lbalmaceda avatar luisrudge avatar mtheoryx avatar nicolagenesin avatar ntotten avatar pose avatar rolodato avatar sre-57-opslevel[bot] avatar widcket avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

password-sheriff's Issues

TypeScript support

Describe the problem you'd like to have solved

Currently, it doesn't support TypeScript

Describe the ideal solution

Provide support for TypeScript

Support passphrases

If password is a passphrase it should not require all that criteria (i.e. numbers, uppercase letters, symbols)

Add maxLength rule

What do you think about adding a max length rule to password-sheriff's policy in order to enable users from submitting arbitrarily large passwords, forcing a server to expensive hash computations that might result to some kind of DoS attack?

I'd be happy to open a PR about that.

Grammar is incorrect

'contain' is repeated at the start of the second rule, when it should start with "at least", like the 1st rule does.

The way it is now "Your password must contain ... contain at least 3 of the 4...."

Screen Shot 2021-02-21 at 12 08 56 AM

Think of it as "Your password must be:" .... "at least..."

Why No FormattedExplain

Instead of making end-users format the message themselves:

var explained = lengthPolicy.explain();
var formatted = util.format(explained[0].message, explained[0].format);

why not simply do it for them?

var formatted = lengthPolicy.formattedExplain();
// or
var formatted = lengthPolicy.explainMessage();
// or
var formatted = lengthPolicy.explanation();

Also, why not allow assert to throw that message? It would reduce:

if (lengthPolicy.check(password)) {
    var explained = lengthPolicy.explain();
    var message = util.format(explained[0].message, explained[0].format);
    throw new Error(message);
}

to simply:

lengthPolicy.assertWithExplanation(password);

I'd be happy to submit a PR if desired.

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.