Giter Club home page Giter Club logo

deno-password-checker's Introduction

Password Checker

CI Quality Gate Status Bugs Reliability Rating Security Rating Maintainability Rating Vulnerabilities Lines of Code Ko-Fi

Deno🦕 module to test if a password/string fulfills all the preset criterias.

Installation

import { checkPassword } from "https://deno.land/x/password_checker/mod.ts";

or

import { checkPasswordWithResult } from "https://deno.land/x/password_checker/mod.ts";

Parameters

Mandatory Parameters:

  • password: string

Optional Parameters:

  • minLen: number - To check the password against a minimum length. Defaults to 0 which disables the check.
  • maxLen: number - To check the password against a maximum length. Defaults to 0 which disables the check.
  • containsNum: boolean - To check if the password contains any numbers. Defaults to true and enables the check.
  • containsSpecialChar: boolean - To check if the password contains any special characters. Defaults to true and enables the check.
  • containsAlphabet: boolean - To check if the password contains any alphabets. Defaults to true and enables the check.
  • checkWithCommonPasswords: boolean - To check if the password is one of the 10000 most common passwords. Need to use --allow-net to use this flag. Defaults to false and disables the check for faster processing.

Output

  • If checkPassword() is invoked:
    • Returns true if password passes all the checks, else false.
  • If checkPasswordWithResult() is invoked:
    • isValid: boolean - true if the password is valid and passes all the checks, else false.
    • reason: string - The reason why the input password was marked as invalid. Returns undefined in case isValid is true.`

Usage

import { checkPassword } from "https://deno.land/x/password_checker/mod.ts";

const passwordString: string = "randomPassword123!.";

let isPasswordValid: boolean;

// Default case which checks if password is alphanumeric and contains special characters
isPasswordValid = checkPassword({ password: passWordString });

// To set minimum length of password
isPasswordValid = checkPassword({ password: passwordString, minLen: 5 });

// To set maximum length of password
isPasswordValid = checkPassword({
  password: passwordString,
  minLen: 5,
  maxLen: 12,
});

// To disable number check on password
isPasswordValid = checkPassword({
  password: passwordString,
  containsNum: false,
});

// To disable alphanumeric check on password
isPasswordValid = checkPassword({
  password: passwordString,
  containsNum: false,
  containsAlphabet: false,
});

// To disable special characters check on password
isPasswordValid = checkPassword({
  password: passwordString,
  containsSpecialChar: false,
});

// To run a check against 10k common passwords
isPasswordValid = checkPassword({
  password: passwordString,
  containsSpecialChar: false,
  checkWithCommonPasswords: true,
});

If you want the reason of failure as well, you can use checkPasswordWithResult() which returns an object of type VerificationResult.

interface VerificationResult {
  isValid: boolean;
  reason?: string;
}

Reference

License

This package is published under the MIT license. For more information, see the accompanying LICENSE file.




PS:

If you find this package useful, please consider giving a star to this project on Github.

And, if you are willing to buy me a coffee, that would be awesome. :)

Buy Me a Coffee at ko-fi.com

deno-password-checker's People

Contributors

arghyadeep-k avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

deno-password-checker's Issues

Reason of failure

Hello, I think it would be great if we could have access to the reason of failure. For instance "password must be longer than x characters", "password must contain at least one special character" and so on.

We could change the return type of checkPassword to something along the lines of

interface VerificationResult {
  isValid: boolean,
  reason: string?
}

Maybe we don't want to change the checkPassword spec, in this case we could create a function checkPasswordWithResult or something like that.

What do you think about it? I can make a PR if you like the idea.

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.