• Stars
    star
    151
  • Rank 245,308 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple npm package that checks the password strength of a certain passphrase. A password strength checker based from Javascript RegEx.

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>

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 RegEx conditions)

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

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

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

Migration from 1.x.x to 2.0.0

// 1.x.x
const whateEverYourFunctionNameWasBefore = require("./index");

// 'contains' attribute of the response object format was
response.contains = [{'message': 'lowercase'}, ...]
// 2.0.0
const { passwordStrength : whateEverYourFunctionNameWasBefore } = require("./index");

// 'contains' attribute of the response object format is now
response.contains = ['lowercase', ...]

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.

More Repositories

1

React.JS-ReduxToolkit-Typescript-CRUD-Sample

This repository provides a basic but dynamic demo & reference for React.JS with Redux Toolkit that performs CRUD (Create, Read, Update & Delete) operations. The project is also using typescript as part of the react template.
TypeScript
26
star
2

ASP.NET-Core-FileUpload-with-VueJS-Axios

Simple ASP.NET Core Project Multiple File Upload with the use of Vue.JS & Axios
JavaScript
14
star
3

Xamarin-Forms-Simple-Login-With-Rest-API

Xamarin forms simple login system connected to rest api. These steps will help you demonstrate and understand the simple logic of login system with only just few codes and snippets.
C#
8
star
4

Xamarin-Forms-Simple-MVVM-Login

This contains sample username and password values as simple representation of using mvvm in building login system.
C#
8
star
5

Check.Password.Strength

.NET package to check the password strength of a certain passphrase. A password strength checker based from System.Text.RegularExpressions.
C#
4
star
6

Xamarin-Forms-Simple-Data-Binding-From-View-Model

C#
3
star
7

capitalize-decapitalize

NPM package for capitalizing or decapitalizing every first letter of the word. Letter case option (Upper & lower case) for every word in a sentence.
JavaScript
3
star
8

ASP.NET-Core-with-Webpack-Babel-ES6-Starter-Project

ASP.NET Core with Installed Webpack, Babel & ES6 using NPM starter project. Feel free to use this project.
JavaScript
3
star
9

Xamarin-Forms-Simple-Maps-And-GeoLocation

C#
2
star
10

get-file-info

A NPM package for getting basic file information like name, size, last modified and type.
JavaScript
2
star
11

SXMvvm-MasterDetailPage

C#
2
star
12

FileUploadAspNetCore

Code sample for uploading files in asp.net core
C#
2
star
13

Steps-In-Creating-Basic-ASP.NET-WebAPI

Here are the simple steps in creating basic custom Asp.Net Web API using Visual Studio.
C#
2
star
14

ASP.NET-Core2.1-WebAPI-and-Angular6-Login-with-Register-SPA

C#
2
star
15

ReactJS-with-MSAL-Connected-to-ASP.NET-Core-with-Azure-AD

TypeScript
2
star
16

SXMvvm-RestClient

C#
1
star
17

value-size

NPM Package for getting the size of an array, object or string.
JavaScript
1
star
18

SavGarder

The Easiest Way To Back Up Your Database
1
star
19

EnumSampleCsharpConsoleApp

C#
1
star
20

Very-Simple-Date-And-Time-Counter-In-Javascript

HTML
1
star
21

deanilvincent.github.io

HTML
1
star
22

ASP.NET-Core-2.1-Sample-App-with-Swagger

C#
1
star
23

Xamarin-Forms-Simple-Local-Notification

C#
1
star
24

random-name-by-country

A simple NPM package for generating random names by country.
JavaScript
1
star
25

XamForms-RealmDb-Mvvm-.Net-Standard

C#
1
star
26

ASP-NET-Core-with-EF

C#
1
star
27

XamFormsWithWebSockets

C#
1
star
28

random-word-by-letter

A NPM package for generating random word by specific letter.
JavaScript
1
star
29

ASP.NET-Core-2.1-WebAPI-Identity-with-JWT

C#
1
star
30

check-password-strength-demo

A demo of the NPM package: https://www.npmjs.com/package/check-password-strength
TypeScript
1
star
31

hey-regex

NPM package that uses Javascript RegEx that checks common inputs like numbers, alpha numeric, email and url.
JavaScript
1
star
32

Xamarin-Forms-Crud-App-With-RealmDB-and-MVVM

C#
1
star
33

ASP.NET-Core-With-WebSockets

This project implements websockets installed. Feel free to clone this project.
C#
1
star
34

spade-fox-blog-template

On-going ...
TypeScript
1
star
35

date-range-diff

Basic simple NPM package in getting date range difference between 2 specific dates.
JavaScript
1
star
36

MissionOnMarsBot

JavaScript
1
star
37

ASP.NET-Core-with-EF-and-WebApi

Basic Template of ASP.NET Core with EF and Web API.
C#
1
star
38

length-distance-converter

NPM package for metric conversions (Length/distance converter).
JavaScript
1
star
39

Xamarin-Forms-HexaDecimalColor-Using-ViewModel

If you want to create hexa decimal color entry and label result then it's bindable to your view model in xamarin forms, this repo will help you out using simple steps.
C#
1
star
40

ReactJs-Alpha-Guide

JavaScript
1
star
41

Passphrase.Generator

NuGet Package for generating passphrase.
C#
1
star
42

age-by-birthdate

A simple NPM package for getting the age by selected birthdate.
JavaScript
1
star
43

ASP.NET-Core-Web-API-with-Angular-Basic-Crud

This sample ASP.NET Core Web API (v3.1) and Angular (v9) with Typescript projects demonstrate a basic implementation of CRUD (Create-Read-Update-Delete) Operations.
TypeScript
1
star
44

ASP.NET-Core2.1-WebAPI-and-Vue.JS-SPA-Basic-CRUD

JavaScript
1
star
45

My-Rest-Client-with-MVVM

This is Rest API with MVVM
C#
1
star