
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
password-sheriff
Advanced tools
Node.js (and browserify supported) library to enforce password policies.
npm install password-sheriff
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));
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.
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
(specialCharacters
are 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.
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.
This project is licensed under the MIT license. See the LICENSE file for more info.
v1.1.1 (2021-09-02)
Changed
util.format
function #27 (stevehobbsdev)Fixed
FAQs
Password policy checker/enforcer.
The npm package password-sheriff receives a total of 29,468 weekly downloads. As such, password-sheriff popularity was classified as popular.
We found that password-sheriff demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 46 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.