项目作者: auth0

项目描述 :
Password policies made easy.
高级语言: JavaScript
项目地址: git://github.com/auth0/password-sheriff.git
创建时间: 2014-05-19T16:28:36Z
项目社区:https://github.com/auth0/password-sheriff

开源协议:MIT License

下载


Password Sheriff

FOSSA Status

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

Install

  1. npm install password-sheriff

Usage

  1. var PasswordPolicy = require('password-sheriff').PasswordPolicy;
  2. // Create a length password policy
  3. var lengthPolicy = new PasswordPolicy({length: {minLength: 6}});
  4. // will throw as the password does not meet criteria
  5. lengthPolicy.assert('hello');
  6. // returns false if password does not meet rules
  7. assert.equal(false, lengthPolicy.check('hello'));
  8. // explains the policy
  9. var explained = lengthPolicy.explain();
  10. assert.equal(1, explained.length);
  11. // easier i18n
  12. assert.equal('lengthAtLeast', explained[0].code);
  13. assert.equal('At least 6 characters in length',
  14. 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:

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

When explained:

  1. var explained = fooRule.explain({count: 5});
  2. // "Foo should be present at least 5 times"
  3. 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.

    1. 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).

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

    1. var charsets = require('password-sheriff').charsets;
    2. var containsAtLeastPolicy = new PasswordPolicy({
    3. containsAtLeast: {
    4. atLeast: 2,
    5. expressions: [ charsets.lowerCase, charsets.upperCase, charsets.numbers ]
    6. }
    7. });
  • identicalChars: Passwords should not contain any character repeated continuously max + 1 times.

    1. var identitcalCharsPolicy = new PasswordPolicy({
    2. identicalChars: {
    3. max: 3
    4. }
    5. });

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