Giter Club home page Giter Club logo

check-password-strength's Introduction

Overview

A simple way to check that password strength of a certain passphrase. A password strength checker based from Javascript RegEx.

Build status

npm Downloads

DEMO 1 by @Ennoriel

DEMO 2

Installation

Install via Package Manager

npm i check-password-strength --save

Install via Browser Script Tag using UNPKG

<script src="https://unpkg.com/check-password-strength/dist/umd.js"></script>
<script type="text/javascript">
    const passwordStrength = checkPasswordStrength.passwordStrength('pwd123').value; // 'Weak'
</script>

Setup & Basic Usage

const { passwordStrength } = require('check-password-strength')
// OR
import { passwordStrength } from 'check-password-strength'

console.log(passwordStrength('asdfasdf').value)
// Too weak (It will return Too weak if the value doesn't match the Weak conditions)

console.log(passwordStrength('asdf1234').value)
// Weak

console.log(passwordStrength('Asd1234!').value)
// Medium

console.log(passwordStrength('A@2asdF2020!!*').value)
// Strong

Additional Info

Object Result

Property Desc.
id 0 = Too weak, 1 = Weak & 2 = Medium, 3 = Strong
value Too weak, Weak, Medium & Strong
contains lowercase, uppercase, symbol and/or number
length length of the password

Password Length Default Options

Name Mininum Diversity Mininum Length
Too weak 0 0
Weak 2 6
Medium 4 8
Strong 4 10
console.log(passwordStrength('@Sdfasd2020!@#$'))
// output 
{ 
    "id": 1, 
    "value": "Strong",
    "contains": ['lowercase', 'uppercase', 'symbol', 'number'],
    "length": 15
}

Default Options

The default symbols are based from Password Special Characters OWASP list (except for the space)

!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~

Thanks for jlherren & Ennoriel for this suggestion! ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป

The default options can be required:

const { defaultOptions } = require("./index");

default options:

[
  {
    id: 0,
    value: "Too weak",
    minDiversity: 0,
    minLength: 0
  },
  {
    id: 1,
    value: "Weak",
    minDiversity: 2,
    minLength: 6
  },
  {
    id: 2,
    value: "Medium",
    minDiversity: 4,
    minLength: 8
  },
  {
    id: 3,
    value: "Strong",
    minDiversity: 4,
    minLength: 10
  }
]

To override the default options, simply pass your custom array as the second argument:

  • id: correspond to the return id attribute.
  • value: correspond to the return value attribute.
  • minDiversity: between 0 and 4, correspond to the minimum of different criterias ('lowercase', 'uppercase', 'symbol', 'number') that should be met to pass the password strength
  • minLength: minimum length of the password that should be met to pass the password strength

The minDiversity and minLength parameters of the first element cannot be overriden (set to 0 at the beginning of the method). Therefore, the first element should always correspond to a "too weak" option.

passwordStrength('myPassword', yourCustomOptions)

RegEx

Strong

 ^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*"'()+,-./:;<=>?[\]^_`{|}~])(?=.{10,})

Medium Password RegEx used:

 ^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*"'()+,-./:;<=>?[\]^_`{|}~])(?=.{8,})
RegEx Desc.
^ The password string will start this way
(?=.*[a-z]) The string must contain at least 1 lowercase alphabetical character
(?=.*[A-Z]) The string must contain at least 1 uppercase alphabetical character
(?=.*[0-9]) The string must contain at least 1 numeric character
(?=.[!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~])) The string must contain at least one special character
(?=.{10,}) The string must be eight characters or longer for Strong strength
(?=.{8,}) The string must be eight characters or longer for Medium strength
(?=.{6,}) Mininum of 6 characters for Weak strength

TypeScript type declarations โ˜‘

Available starting version v2.0.3 and above. (Thanks to @Mesoptier!)

Other resources

For .NET Project

If you're working with .net core project, I've created a simple nuget package with same RegEx strings to validate a password strength.

You can easily install via Nuget Package Manager or .NET CLI (Check.Password.Strength). This package uses Regular Expression new Regex() derives from System.Text.RegularExpressions. You can use this especially if you want to validate the passcode strength on backend services or web apis of your project.

Other NPM RegEx validator

I also made another NPM package (hey-regex) that checks common inputs like numbers (whole number and decimal), alpha numeric, email and url. This package only returns true or false based from the selected function (with RegEx .test() inside).

Reference blog.

Contribute

Feel free to clone or fork this project: https://github.com/deanilvincent/check-password-strength.git

Contributions & pull requests are welcome!

I'll be glad if you give this project a โ˜… on Github :)


Kudos to @Ennoriel and his efforts for making v2.x.x possible!

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

check-password-strength's People

Contributors

adoliin avatar capaj avatar cmorford avatar deanilvincent avatar dependabot[bot] avatar ennoriel avatar mesoptier avatar newyork-anthonyng 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  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

check-password-strength's Issues

Is there a reason this does not run in NodeJS ?

I am wondering if there is a reason why this package does not run not in NodeJs ?
when i install and then run your sample code like

const passwordStrength = require('check-password-strength')
console.log(passwordStrength('asdfasdf').value)

TypeError: passwordStrength is not a function

Import is not working with Bundler

Im forced to import this like: import { passwordStrength } from 'check-password-strength/dist'
Before version "2.0.8" was like: import { passwordStrength } from 'check-password-strength'

Im using nuxt 3 and as you can read here they use a different bundler:
https://github.com/nuxt/nuxt/releases/tag/v3.10.0

๐Ÿ“ฆ Bundler module resolution
With nuxt/nuxt#24837, we are now opting in to the TypeScript bundler resolution which should more closely resemble the actual way that we resolve subpath imports for modules in Nuxt projects.

'Bundler' module resolution is recommended by Vue and by Vite, but unfortunately there are still many packages that do not have the correct entries in their package.json.

Wrong default value

According to Readme you have wrong default value for password strength.
Right now it is { id: 2, value: 'Weak }. Should be Strong. Add some test to it please :)

Password strenght special chars

Hi,

what would be the drawbacks in using this instead?
^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[^a-zA-Z0-9])(?=.{10,})

Thanks

v2.0.9 breaking changes

I just upgraded from v2.0.7 to v2.0.9, and it appears the changes related to ESM (perhaps?) now cause a critical error on app build.

@deanilvincent @Ennoriel Why were these changes marked as a patch version update and not a major update given the breaking changes?

EDIT: appears that the removal of the default export was perhaps the issue? I see this is identified in the setup docs, but was not called out in the release notes.

Make the lib configurable

Hello!

Your library does a great job!

I would be glad to make a PR to make it configurable, say with a parameter

[
  {
     id: 0,
     value: 'Weak',
     requires: ['lowercase', 'uppercase']
     length: 5
  },...
]

It would be retrocompatible with a default parameter set as the actual configuration.

What do you think?

UMD version?

Hi there,

Thank you for a nicely written library :)

Would you be keen to release an UMD version of the library too so it can be easily embed on a site through a CDN link?

Some special characters are transformed.

Hello,

thanks for your librairy, it's really nice.

I just noticed that the 3 following characters are "transformed" after a user choose them in his password :

< is transformed in &lt;
> is transformed in &gt;
& is transformed in &amp;

Example : a user chooses the password password@444&, then the passwordStrength checking actually checks password@444&amp;. Then, some medium passwords become strong because of length.

What can we do ?

Julien

Symbol : equal

Hi,

The equal (=) symbol does not seem to be included in your regexp that checks for symbols.

Is it on purpose ?

If not could you add it ?

Thanks a lot

List of default symbols seems arbitrarily restrictive

By default only the characters !@#$%^&* are considered "symbols". I know that this can be overridden as desired, but is there a reason why this list is so restrictive by default? E.g., why are all the following characters not considered symbols?

"'()+,-./:;<=>?[]_`{|}~

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.