npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@codecafe/password-checker

v1.0.6

Published

> A class that can be instantiated as a password checker by pass some check options in, and we can use this checker to check our password, or rate it.

Downloads

3

Readme

CodeCafe Password Checker

A class that can be instantiated as a password checker by pass some check options in, and we can use this checker to check our password, or rate it.

Installing

For the latest stable version:

Using npm:

npm install --save @codecafe/password-checker

or simply using this:

npm i @codecafe/password-checker

or using yarn:

yarn add @codecafe/password-checker

Instantiation

To use password checker, you need to import @codecafe/password-checker to your project first, and then instantiated it with the options parameter.

For example:

import PasswordChecker from '@codecafe/password-checker';

const pwc = new PasswordChecker({
    allowedSymbols: ['_', '-', '!', '@', '#', '$', '%', '^', '&', '*', '?'],
    lengthRange: [8, 18],
    letterRange: ['a', 'z'],
    LetterRange: ['A', 'Z'],
    numberRange: ['0', '9'],
    repetitionLength: 3,
    numberConsecutionLength: 3,
    letterConsecutionLength: 4,
});

we call the options parameter interface IPasswordCheckerOptions:

interface IPasswordCheckerOptions {
    // all allowed non-alphanumeric symbols list
    allowedSymbols: string[];
    // range of allowed numbers, [start, end]
    numberRange: [string, string];
    // range of allowed lowercase letters, [start, end]
    letterRange: [string, string];
    // range of allowed capital letters, [start, end]
    LetterRange: [string, string];
    // range of the allowed password length, [min, max]
    lengthRange: [number, number];
    // maximum allowable length of the character repetition(not include the max value)
    repetitionLength: number;
    // maximum allowable length of the consecution of the number characters(not include the max value)
    numberConsecutionLength: number;
    // maximum allowable length of the consecution of the letters(not include the max value)
    letterConsecutionLength: number;
}

we supported an instantiated implementation of this interface as the default options object:

const defaultPasswordCheckerOptions: IPasswordCheckerOptions = {
    allowedSymbols: ['_', '-', '!', '@', '#', '$', '%', '^', '&', '*', '?'],
    lengthRange: [8, 18],
    letterRange: ['a', 'z'],
    LetterRange: ['A', 'Z'],
    numberRange: ['0', '9'],
    repetitionLength: 3,
    numberConsecutionLength: 3,
    letterConsecutionLength: 4,
}

so that you can just pass in the modified part of all the properties of this interface, or even pass none:

const pwc = new PasswordChecker({
    allowedSymbols: ['_', '-', '!', '@', '#', '$', '%', '^', '&', '*', '?'],
    lengthRange: [8, 18],
});
const pwc = new PasswordChecker();

we will fill the rest properties from the object defaultPasswordCheckerOptions in.

After the object has been instantiated, we could get the regular of this checker:

class PasswordChecker {
    // the regular for checking the characters set and length
    charsAndLengthPattern: RegExp

    // the regulars for checking charecter types
    classifiedCharsPatterns: RegExp[]

    ...
}

this two properties are readonly, you can not change it after the object has been instantiated.

Checking your password

There are 4 check methods to check your password, they are:

checkLength, which can check whether your password length is out of the legal length, and return the length of out part:

checkLength(password: string): number;

checkCharsSetAndLength, which is used to check whether the characters set and length of your password are all legal:

checkCharsSetAndLength(password: string): boolean;

checkRepetition, which to be used in checking if there are one or more repetitions of same character in your password:

checkRepetition(password: string): boolean;

checkCharConsecution, which to be used in checking if there are one or more consecutions of the consecutive numbers or letters in your password:

checkCharConsecution(password: string): boolean;

Rating youe password

You can use the getLevel method to get the level of your password:

getLevel(password: string): number

for example:

const level = pwc.getLevel('aabbcc1122!!CCBBAA');

console.log(level) // print 4

Rating details

You must be wondering why your password get such a rate level, everyone has such a doubt, and we got it. We designed a class PasswordLevelCheckDetails to show you the level details of your password. you can't instantiated it by self, but you can get the instance of it after each time you called the getLevel method, here is the codes:

const level = pwc.getLevel('aabbcc1122!!CCBBAA', details);
const details = pwc.lastLevelDetails;

console.log(details)
/*
print PasswordLevelCheckDetails {
    legal: true,
    outOfLength: 0,
    charTypesCount: 4,
    hasRepetition: false,
    hasCharConsecution: false,
}
*/

class PasswordLevelCheckDetails is a implementation of interface ILevelDetails:

interface ILevelDetails {
    // is the password legal in characters set and length
    legal: boolean
    // the length of out part
    // if the actual length is grater then the legal length, it will be a positive integer, which is the actual length subtracts the max vlaue of the legal length range,
    // or if the actual length is less then the legal length, it will be a negative integer, which is the actual length subtracts the min vlaue of the legal length range,
    // or it will be zero
    outOfLength: number
    // how many char types the password has?
    // there are four types in all,
    // they are numbers, lowercase letters, capital letters and other symbols
    charTypesCount?: number
    // if the password has one or more repetitions of same character
    hasRepetition?: boolean
    // if the password has one or more consecutions of the consecutive numbers or letters
    hasCharConsecution?: boolean
}