A simple interface module that creates password-policy for your application.

Overview

password-policy-setter

A simple interface module that creates password-policy for your application.

INTRODUCTION

This module is a simple alternate to creating complex native Regex, or tedious multidimensional checks on password-string to check required elements.

USAGE

  1. Require the module.
  2. Use the init method to pass arguments determining the policy.
  3. Then use the satisfied method to check whether or not the password-policy is satisfied.
  4. Alternatively, can use the findAnomaly method, to know which conditions are fulfilled and which aren't via an object returned.

PARAMETERS

1.  size       : MANDATORY |                 | e.g. 8          => The minimum character length of the password.
2.  lower      : OPTIONAL  |  or    | default : false | e.g. true/3       => The password must contain at least n lowercase character, where n is the value passed.
3.  upper      : OPTIONAL  |  or    | default : false | e.g. true/1       => The password must contain at least n uppercase character, where n is the value passed.
4.  numbers    : OPTIONAL  |  or    | default : false | e.g. true/1       => The password must contain at least n numeral character, where n is the value passed.
5.  splChar    : OPTIONAL  |  or    | default : false | e.g. false/0      => The password must contain at least n special character (character other than A-Z, a-z, 0-9), where n is the value passed.

Note:

  1. negative numbers will be treated as 0.
  2. any positive number will be treated as true, and the no. of times that character should be present in the string.

EXAMPLE

const ppSetter = require ('password-policy-setter');

let condition = {
  size    : 8,
  lower   : true, // or 2
  upper   : true, // or 1
  numbers : true, // or 1
	splChar : true, // or 1
};


let notokcondition = {
  size     : 8,
	lower    : true,
	upper    : true,
	numbers  : true,
	splChars : true,
};

ppSetter.init(condition);

let okpwd = "Ab@4_eF7.k";
let notokpwd = 'AB3DeF8D';

 ppSetter.satisfied (okpwd);    // returns true;
 ppSetter.satisfied (notokpwd); // returns false;

 ppSetter.findAnomaly (okpwd);    // returns { size: true, lower: true, upper: true, numbers: true}
 ppSetter.findAnomaly (notokpwd); // returns { size: true, lower: false, upper: true, numbers: true}
 
 ppSetter.init (notokcondition); // errorState, thus any subsequent call to any of the policy methods will early return with error object.
 ppSetter.satisfied (okpwd);     // returns {message : 'Unknown or Unidentified condition passed, exiting', key : 'splChars'}
 ppSetter.satisfied (notokpwd);  // returns {message : 'Unknown or Unidentified condition passed, exiting', key : 'splChars'}

PATCH NOTES

2.3.1

  1. Only size param mandatory, rest optional, with default value of false.
  2. Can pass either a boolean or number as param value.
  3. Ability to specify the number of times a certain character-type should be present.

2.3.2

  1. Bug fix.
  2. Upper limit added too (1000).
  3. In findAnomaly, only the keys with a non-false or non-zero value will be shown, previously all keys were shown with a default value false.

2.3.5

  1. Fixed all bugs.
  2. Stable version.
You might also like...

🤖 GitHub Action which creates Issues from comments in your code

🤖 GitHub Action which creates Issues from comments in your code

todo-issue[action] Disclosure Huge thanks to JasonEtco! After he decided to shut down his todo[bot] I've looked around for alternatives but decided to

Dec 11, 2022

This Photoshop script exports all top-level layers and groups to cropped PNG and JPEG files and creates a file usable in Tumult Hype 4 based on your Photoshop document.

This Photoshop script exports all top-level layers and groups to cropped PNG and JPEG files and creates a file usable in Tumult Hype 4 based on your Photoshop document.

Export To Hype (Photoshop Edition) This Photoshop script exports all top-level layers and groups to cropped PNG and JPEG files and creates a file usab

Nov 9, 2022

Password Generator - A fast, simple and powerful open-source utility tool for generating strong, unique and random passwords

A fast, simple and powerful open-source utility tool for generating strong, unique and random passwords. Password Generator is free to use as a secure password generator on any computer, phone, or tablet.

Aug 3, 2022

Template Repository for making your own budder Module. CORE is not included, this is just for the module.

A quick copy of the "How to make your own module" section Check out the official budderAPI repository Template Repository for making your own budder M

Apr 3, 2022

Generate a secured base32 one time password to authenticate your user! 🔐

Django SOTP 🔐 Generate a secured base32 one time password to authenticate your user! Case Study 📑 Before I mention why you should use django-sotp in

Dec 22, 2022

Check the strength of your password simply and quickly, and with optional UI indicators

Check the strength of your password simply and quickly, and with optional UI indicators. Lock Steel is lightweight, has no dependencies and is connected with the UI elements. Just pure CSS and VanillaJS.

Sep 15, 2022

Create your own password generator using jQuery, Vanilla JS, and SASS.

Password Generator Create your own password generator using jQuery, Vanilla JS, and SASS. I have been working with JS for my last few projects so I th

Jul 12, 2021

Select creates a dropdown list of items with the selected item in closed view.

Select creates a dropdown list of items with the selected item in closed view.

Native Base Select 🔽 This module includes a customizable multi-select and a single select component for Native Base. The package is both Android and

Dec 25, 2022

An obsidian plugin that creates tomorrows daily note for preemtive planning.

An obsidian plugin that creates tomorrows daily note for preemtive planning.

Tomorrow's Daily Note An Obsidian plugin that creates tomorrows daily note for preemtive planning. Requirements Obsidian v0.12.0+. Daily notes plugin

Sep 24, 2022
Comments
  • Suggestion to improve API to handle multiple separate policies together

    Suggestion to improve API to handle multiple separate policies together

    According to the current implementation, the user has to call .init(policy) explicitly before they want to validate for a specific policy which does not seem very elegant. Either this should be mentioned explicitly or the API can be modified to eliminate users to make mistakes which is much better.

    const policySetter = require ('password-policy-setter');
    
    const verificationCodePolicy = {
       size    : 6,
       lower   : false,
       upper   : true,
       numbers : false,
       splChar : false,
    }
    const signupPasswordPolicy = {
       size    : 15,
       lower   : 1,
       upper   : 1,
       numbers : 1,
       splChar : 1,
    }
    
    const inputVerificationCode = 'SECRET';
    const inputSignupPassword = 'SecretP@assword'
    
    policySetter.init(verificationCodePolicy);
    
    if (!policySetter.satisfied(inputVerificationCode))
       throw new Error('Invalid verification code');
    
    // ⚠️ explicity remeber to change policy as module keeps track of last set policy
    policySetter.init(signupPasswordPolicy);
    
    if (!policySetter.satisfied(inputSignupPassword))
       throw new Error('Invalid signup password');
    

    Suggestion

    I would suggest keeping the library stateless and delegating state handling to the user's application.

    const PolicySetter = require ('password-policy-setter');
    /* This forces the user to handle policy state and gets rid of global state management from the library*/
    
    const verificationCodePolicySetter = new PolicySetter(verificationCodePolicy);
    verificationCodePolicySetter.satisfied(inputVerificationCode);
    verificationCodePolicySetter.findAnomaly(inputVerificationCode);
    
    const signupPasswordPolicySetter = new PolicySetter(signupPasswordPolicy);
    signupPasswordPolicySetter.satisfied(inputSignupPassword);
    signupPasswordPolicySetter.findAnomaly(inputSignupPassword);
    
    

    Another way could be to remove direct access to satisfied()/findAnomaly() and to force users to explicitly set policy every time they want to check some input.

    policySetter.init(verificationCodePolicy).satisfied(inputVerificationCode);
    policySetter.init(verificationCodePolicy).findAnomaly(inputVerificationCode);
    
    policySetter.init(signupPasswordPolicy).satisfied(inputSignupPassword);
    policySetter.init(signupPasswordPolicy).findAnomaly(inputSignupPassword);
    
    opened by griimick 1
Owner
Snigdh Shourya
Snigdh Shourya
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Demo showcasing information leaks resulting from an IndexedDB same-origin policy violation in WebKit.

Safari 15 IndexedDB Leaks Description This demo showcases information leaks resulting from an IndexedDB same-origin policy violation in WebKit (a brow

FingerprintJS 101 Nov 5, 2022
Creates Photoshop-like guides and rulers interface on a web page

RulersGuides.js This Javascript package creates Photoshop-like guides and rulers interface on a web page. DEMO Main window: Menu: Guides are created b

Mark Rolich 925 Nov 27, 2022
This package creates embeds and buttons in a very simple way using the whatsapp-web.js module for whatsapp

This package creates embeds and buttons in a very simple way using the whatsapp-web.js module for whatsapp

DeathAbyss 17 Jan 3, 2023
An npm package for demonstration purposes using TypeScript to build for both the ECMAScript Module format (i.e. ESM or ES Module) and CommonJS Module format. It can be used in Node.js and browser applications.

An npm package for demonstration purposes using TypeScript to build for both the ECMAScript Module format (i.e. ESM or ES Module) and CommonJS Module format. It can be used in Node.js and browser applications.

Snyk Labs 57 Dec 28, 2022
More than a Password Protection and Management tool, it secures all your valuable digital assets in your own vault

ZeroPass Client ZeroPass is more than a Password Protection and Management tool, it secures all your valuable digital assets in your own vault, includ

null 6 Aug 22, 2022
A simple code that creates a string of random characters displayed in an html object, all saving in a json file.

I'm 17 Years Old Developer / Lead Developer. ?? I'm wroking on AdrenalinaRP, GrandRDM. ?? I’m currently learning JavaScript. ?? I’m looking to collabo

OFFVIXEN 2 Nov 17, 2022
VSCode extension that creates overlay for your Broadcasting Software of choice.

BSOverlay VSCode extension that creates an overlay for your Broadcasting Software of choice. Documentation Please refer to the Wiki Section. Installin

chocoearly44 4 Sep 30, 2022