Policy-password is a NodeJS library written in Typescript to generate passwords according to policies and constraints.

Overview

PolicyPassword
policy-password is a library to generate passwords
from policies given constraints.

Contributing Guidelines · Submit an Issue


The purpose of this library is to provide a powerful password generator based on a PasswordPolicy configuration. This especially useful when using a library such as keycloak. Keycloak provides the ability to set password policies per realm which can be obtained and parsed to generate passwords with this library.

FOSSA Status Lint and test CodeQL codecov npm version npm downloads npm dependencies

Installation

To install this library, run

yarn add policy-password
yarn install

or

npm i policy-password

depending on your package manager.

Usage

This library provides a class and a function based approach to generate passwords and/or policies. Generally, we need to build our policy first which we can then use to generate a password from.

generateCompliantPassword({ policy[, constraints, includeList, excludeList, samplePolicy] })

Generate a single password given the passwordPolicy and the minPolicyConstraints from the GeneratorConfig.

/* Policy dictates that we want a password that is at least six characters long
   with a minimum of two special characters, two digits and two uppercase
   letters.
 */
const policy: Policy = {
  special: 2,
  digit: 2,
  upper: 2,
};
/* Prepare our config that holds the policy for password generation.
 */
const config: GeneratorConfig = { policy, samplePolicy: true };
/* Generate 35 passwords with our predefined policy atop.
 */
const password: Password = generateCompliantPassword(config);

new PasswordGenerator({ policy[, constraints, includeList, excludeList, samplePolicy] }).generate()

/* Policy dictates that we want a password that is at least 12 characters long
   with a minimum of two two digits and two uppercase letters.
 */
const policy: Policy = {
  length: 12,
  digit: 2,
  upper: 2,
};
/* We want to have a constraint of minimum eight lowercase characters but only
   with letters [a-m] and not so fancy special chars.
 */
const config: GeneratorConfig = {
  policy,
  samplePolicy: true,
  includeList: {
    ...defaultIncludeList,
    special: '!?#+-_',
    lower: 'abcdefghijklm',
  },
};
const passwordGenerator = new PasswordGenerator(config);
const password: Password = passwordGenerator.generate();

Configuration options with GeneratorConfig

No matter the method you choose to generate a password, you always have to provide a GeneratorConfig. An overview of the various configuration options is outlined in this table:

Option name Type Description Default value Required
policy Policy | DefinitePolicy The policy that dictates the length and character pool for your generated passwords. {} yes
constraints Constraints Constraints consist of mandatory minimum and maximum constraints. Constraints can be used to sample a policy when the samplePolicy flag is set to true. policyNistRecommendations (see constants.ts for more information) no
includeList IncludeList An object that maps the individual quantifiable keys (upper, lower, digit, special) onto valid characters. The include list spans the pool of characters which are used to build the generated password. defaultIncludeList (see constants.ts for more information) no
excludeList ExcludeList An array of characters to exclude from generated passwords. Takes precedence over the given or default include list. [] no
samplePolicy boolean A flag to control whether a policy should be sampled from given or default constraints. false no

How to run an example

You can run an example, e.g. the function/password.example.ts in the examples folder like so:

yarn run example:func

Development

In case you want to develop on or contribute to this library, make sure to check out the remote HEAD and install all dependencies with your favorite package manager for NodeJs. To run this application type

yarn start

or

npm start

Testing

To run the test suite of this library, type

yarn test

or

npm test

Code style & lint

Please pay attention to the .editorconfig and .eslintrc.js and stick to those rules. PR's in that regard are welcome as well!

Author

Thomas Hesse

License

FOSSA Status

You might also like...

Optimized DNS/HTTP Log Tool for pentesters, faster and easy to use.

Optimized DNS/HTTP Log Tool for pentesters, faster and easy to use.

Optimized DNS/HTTP Log Tool for pentesters, faster and easy to use.

Dec 9, 2022

Generate Password is a generating random and unique passwords.

Generate Password Generate Password is a generating random and unique passwords. Install $ npm install @wcj/generate-password --save Usage import { ge

Jun 16, 2022

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

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

Oct 27, 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

A postgraphile plugin that allows you to expose only a single direction of connections exposed by foreign key constraints

A postgraphile plugin that allows you to expose only a single direction of connections exposed by foreign key constraints

Mar 13, 2022

Utility for collecting resource-based policies from an AWS account

AWS resource-based policy collector This library aims to collect resource-based policies from an AWS account. NOTE: This library does not cover all AW

Dec 5, 2022

Application to generate secure passwords based on the 'KDF' strategy.

PasswordGenerator This project was generated with Angular CLI version 12.2.6. Development server Run ng serve for a dev server. Navigate to http://loc

Aug 14, 2022

IAM policy actions autocomplete, documentation & wildcard resolution

IAM policy actions autocomplete, documentation & wildcard resolution

IAM Legend AWS IAM actions autocomplete, documentation and wildcard resolution for Visual Studio Code. Supports Serverless Framework, AWS SAM, CloudFo

Dec 28, 2022

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

Nov 5, 2022

Detect browser, and render view according to the detected browser type.

react-browser-detector Detect browser, and render view according to the detected browser type. Installation To install, you can use npm or yarn: npm i

Jul 13, 2022

In this project, I built a simple HTML list of To Do tasks. The list is styled according to the specifications listed later in this lesson. This simple web page is built using webpack and served by a webpack dev server.

Awesome books:JavaScript Using Modules In this project, I built a simple HTML list of To Do tasks. The list is styled according to the specifications

Nov 25, 2022

Link your position on a mcbe server to a discord voice. The sound changes according to the distance to the nearest players.

DiscordLink Link your position on a mcbe server to a discord voice. The sound changes according to the distance to the nearest players. Credits - No I

May 28, 2022

Simple validator for Steuerliche Identifikationsnummer (German personal tax number) according to the official docs (see readme).

simple-de-taxid-validator Important Code of this validator is taken (with small changes like optimization or removing not needed elements) from THIS R

Feb 24, 2022

Add icons to the AtCoder standings table according to ratings.

Add icons to the AtCoder standings table according to ratings.

ac-rating-icon AtCoder のコンテスト順位表に、レーティングに対応したアイコンを追加するユーザースクリプトです。 アイデア元: https://twitter.com/e869120/status/1519310341024677888 灰色の細分化について 内部レート 0 以上

May 6, 2022

Personal project to a student schedule classes according his course level. Using GraphQL, Clean Code e Clean Architecture.

Personal project to a student schedule classes according his course level. Using GraphQL, Clean Code e Clean Architecture.

classes-scheduler-graphql This is a personal project for student scheduling, with classes according his course level. I intend to make just the backen

Jul 9, 2022

A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and configure Typescript on it.

A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and configure Typescript on it.

CTSP- Create TS Project A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and conf

Sep 13, 2022

jQuery plugin to encourage strong user passwords

Naked Password¶ ↑ Simple jQuery plugin to improve security on passwords. Usage¶ ↑ Naked password is extremely easy to use. All thats needed is for you

Nov 3, 2022

A free & open source project to save your passwords, notes & credit cards

Free & open source project to save your passwords, notes & credit cards with a clean console UI with multiples features such as show information/create information/delete information

Aug 8, 2022
Comments
  • Add license scan report and status

    Add license scan report and status

    Your FOSSA integration was successful! Attached in this PR is a badge and license report to track scan status in your README.

    Below are docs for integrating FOSSA license checks into your CI:

    opened by fossabot 1
  • chore(deps): bump minimatch from 3.0.4 to 3.1.2

    chore(deps): bump minimatch from 3.0.4 to 3.1.2

    Bumps minimatch from 3.0.4 to 3.1.2.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • fix: codecov test coverage

    fix: codecov test coverage

    Fix similar to https://github.com/sinkcup/coverage-badge/pull/22/commits/d89470e7357e64a8db538d1db54d10d3b9fe743b Upload lcov.info instead of clover.xml.

    opened by tahesse 0
  • Fix indeterministic password test case

    Fix indeterministic password test case

    https://github.com/tahesse/policy-password/blob/main/test/password.test.ts#L95-L104

    is not deterministic and can cause the CI pipeline to fail. Suggested solution:

    Add a boolean flag to circumvent this issue and provide users of this library to prevent uni-letter passwords.

    bug enhancement help wanted 
    opened by tahesse 0
Owner
Thomas Hesse
Check out my LinkedIn for a bio: https://www.linkedin.com/in/tahesse/
Thomas Hesse
📡 Encrypt and authenticate DevTools to use it securely remotely. Add HTTPS, and authentication to --remote-debugging-port to debug, inspect and automate from anywhere and collaborate securely on bugs.

?? Encrypt and authenticate DevTools to use it securely remotely. Add HTTPS, and authentication to --remote-debugging-port to debug, inspect and automate from anywhere and collaborate securely on bugs.

Cris 9 May 5, 2022
DOMPurify - a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG. DOMPurify works with a secure default, but offers a lot of configurability and hooks. Demo:

DOMPurify DOMPurify is a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG. It's also very simple to use and get started with

Cure53 10.2k Jan 7, 2023
Clean up user-submitted HTML, preserving whitelisted elements and whitelisted attributes on a per-element basis. Built on htmlparser2 for speed and tolerance

sanitize-html sanitize-html provides a simple HTML sanitizer with a clear API. sanitize-html is tolerant. It is well suited for cleaning up HTML fragm

Apostrophe Technologies 3.2k Dec 26, 2022
AnonCrypt ciphers and diciphers your messages or strings which makes you send texts to people without them understanding it.

AnonCrypt ciphers and diciphers your messages or strings which makes you send texts to people without them understanding it. Anoncrypt uses Aes192 cipher encryption type and not Hmac.

AnonyminHack5 11 Oct 23, 2022
Ganache is an Ethereum simulator that makes developing Ethereum applications faster, easier, and safer

Ganache is an Ethereum simulator that makes developing Ethereum applications faster, easier, and safer. It includes all popular RPC functions and features (like events) and can be run deterministically to make development a breeze.

Truffle Suite 2.2k Jan 7, 2023
A WebApp that allows you to follow Cryptos' News and Stats

CryptoWatch A WebApp that allows you to follow Cryptos' News and Stats. Table of Contents About The Project Screenshots Built With Getting Started Pre

null 28 Aug 4, 2022
Smart contracts for governance. Contract allows to bond custom/LP UNI-v2 tokens and get voting power

Smart contracts for governance. Contract allows to bond custom/LP UNI-v2 tokens and get voting power

Rinat Fihtengolts 3 Oct 2, 2022
A full stack digital marketplace running on Ethereum, built with Polygon, Next.js, Tailwind, Solidity, Hardhat, Ethers.js, and IPFS

A full stack digital marketplace running on Ethereum, built with Polygon, Next.js, Tailwind, Solidity, Hardhat, Ethers.js, and IPFS

Christotle Agholor 32 Dec 27, 2022
Build a Cryptocurrency Tracker with Next.js and GraphQL

Build a Cryptocurrency Tracker with Next.js and GraphQL This is the complete code to my blog post on Medium on "Build a Cryptocurrency Tracker with Ne

Presterud Myrseth Technologies 4 Dec 1, 2022
A Secure Web Proxy. Which is fast, secure, and easy to use.

Socratex A Secure Web Proxy. Which is fast, secure, and easy to use. This project is under active development. Everything may change soon. Socratex ex

Leask Wong 222 Dec 28, 2022