Skip to main content

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 matches the preset criterias.

Installation

import { checkPassword } 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.

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 the checck against 10k common passwords
isPasswordValid = checkPassword({
  password: passwordString,
  containsSpecialChar: false,
  checkWithCommonPasswords: true,
});

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