Socket
Book a DemoInstallSign in
Socket

pwd-strength

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pwd-strength

This module takes a password string and validate it according to the specified rules.

1.1.2
latest
Source
npmnpm
Version published
Weekly downloads
142
-20.67%
Maintainers
1
Weekly downloads
 
Created
Source

pwd-strength

This module takes a password string and validate it according to the specified rules.

Install

npm install --save pwd-strength

Settings

Here is a list of the settings currently available:

SettingDefaultDescription
debugfalseEnable debug mode
allErrorsfalseShow all errors found as an array instead the first one as string
minUpperChars1Minimum uppercase characters required [A-Z].
minLowerChars1Minimum lowercase characters required [a-z].
minNumberChars1Minimum numbers required [0-9].
minSpecialChars1Minimum symbols required (any character not in [a-zA-Z0-9]).
minPasswordLength8Minimum password length required.
maxConsecutiveRepeatingChars2Maximum consecutive repeating characters allowed.
langSee belowObject with multi-language strings.
colorsSee belowObject with the colors depending on the strength.

Language settings

Here is a list of the language settings currently available:

Language settingTranslation
weakWeak
averageAverage
strongStrong
secureSecure
enterPasswordEnter a password
minPasswordCharAt least %s character please
minPasswordCharsAt least %s characters please
minLowerCharAt least %s lowercase character please
minLowerCharsAt least %s lowercase characters please
minUpperCharAt least %s uppercase character please
minUpperCharsAt least %s uppercase characters please
minNumberCharAt least %s number please
minNumberCharsAt least %s numbers please
minSpecialCharAt least %s special character please
minSpecialCharsAt least %s special characters please
maxConsecutiveRepeatingCharsNo more than %s consecutive repeating characters or numbers please

Color settings

Here is a list of the color settings depending on the strength currently available:

Color settingDefault
error#ee0000
weak#c43d4b
average#cc9900
strong#569f0c
secure#007000

Testing the library

    const passwordStrength = require('pwd-strength');
    
    let result = passwordStrength('Test');

The function returns an object as follows:

Error response

    {
        "success": false, // any error occurs
        "key": "error", // Indicates error
        "message": "First error message found", // Multilanguage string with the error message
        "color": "#rrggbb" // Hex color depending on the key
    }

Error response with allErrors: true setting

    {
        "success": false, // any error occurs
        "key": "error", // Indicates error
        "message": ["Error message 1", "Error message 2", "Error message 3", ...], // Multilanguage array of strings with the error messages
        "color": "#rrggbb" // Hex color depending on the key
    }

Success response

    {
        "success": true, // no errors
        "key": "weak|average|strong|secure", // Indicates the strength
        "message": "Strength", // Multilanguage string with the strength
        "color": "#rrggbb" // Hex color depending on the key
    }

Error examples

Default settings, the first error checked will be the empty password:

    console.log(passwordStrength(''));
    // {"success":false,"key":"error","message":"Enter a password","color":"#ee0000"}

Default settings, the first error checked will be the password length:

    console.log(passwordStrength('Test'));
    // {"success":false,"key":"error","message":"At least 8 characters please","color":"#ee0000"}

Minimum uppercase characters:

    console.log(passwordStrength('testtest', { minUpperChars: 1 }));
    // {"success":false,"key":"error","message":"At least 1 uppercase character please","color":"#ee0000"}

Minimum lowercase characters:

    console.log(passwordStrength('TESTTEST', { minLowerChars: 1 }));
    // {"success":false,"key":"error","message":"At least 1 lowercase character please","color":"#ee0000"}

Minimum numbers:

    console.log(passwordStrength('TestTest', { minNumberChars: 1 }));
    // {"success":false,"key":"error","message":"At least 1 number please","color":"#ee0000"}

Minimum symbols:

    console.log(passwordStrength('TestTest1', { minSpecialChars: 1 }));
    // {"success":false,"key":"error","message":"At least 1 special character please","color":"#ee0000"}

Maximum consecutive repeating characters allowed:

    console.log(passwordStrength('TestTTTTest1', { maxConsecutiveRepeatingChars: 2 }));
    // {"success":false,"key":"error","message":"No more than 2 consecutive repeating characters or numbers please","color":"#ee0000"}

With allErrors: true setting and the empty password, all possible errors will be shown, only in an error occurs (success: false in the response). This is the only case where the message property will be an array of strings.

    console.log(passwordStrength('', { allErrors: true }));
    // {"success":false,"key":"error","message":["Enter a password","At least 8 characters please","At least 1 lowercase character please","At least 1 uppercase character please","At least 1 number please","At least 1 special character please"],"color":"#ee0000"}

Success examples

Success result, with weak password:

    console.log(passwordStrength('testtest', { minUpperChars: 0, minSpecialChars: 0, minNumberChars: 0 }));
    // {"success":true,"key":"weak","message":"Weak","color":"#c43d4b"}

Success result, with average password:

    console.log(passwordStrength('testest1', { minUpperChars: 0, minSpecialChars: 0 }));
    // {"success":true,"key":"average","message":"Average","color":"#cc9900"}

Success result, with strong password, and default settings:

    console.log(passwordStrength('TestTest1!'));
    // {"success":true,"key":"strong","message":"Strong","color":"#569f0c"}

Success result, with secure password, and default settings:

    console.log(passwordStrength('Test123%$/)=!'));
    // {"success":true,"key":"secure","message":"Secure","color":"#007000"}

Keywords

password

FAQs

Package last updated on 18 Jun 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.