JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 42125
  • Score
    100M100P100Q151821F
  • License MIT

Zero-dependency utilities for generating secure passwords and pins

Package Exports

  • secure-password-utilities
  • secure-password-utilities/lib/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (secure-password-utilities) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

secure-password-utilities

Zero-dependency utilities for generating secure passwords and pins.

Usage

npm install secure-password-utilities

Basic usage:

import {generatePassword, generatePin} from 'secure-password-utilities';

// Default length is 12.
// Defaults include all uppercase/lowercase characters, digits, and symbols.
const password = generatePassword();
console.log(password); // l[Nz8UfU.o4g

const pin = generatePin(6);
console.log(pin); // 036919

API

generatePassword(options: PasswordOptionsType): string

Generates a random password.

PasswordOptionsType is defined as:

type PasswordOptionType =
  // `true` means include [character type], `false` means exclude [character type]
  | boolean
  // <number> means include exactly <number> [character type]s
  | number
  // { min: <number> } means include at least <number> [character type]s
  | { min: number };

type PasswordOptionsType = {
  length: number;
  digits: PasswordOptionType;
  symbols: PasswordOptionType;
  lowercase: PasswordOptionType;
  uppercase: PasswordOptionType;
};

Examples:

// Contains only letters (upper and lowercase) and digits.
const alphanumericPassword = generatePassword({ length: 10, symbols: false});
console.log(alphanumericPassword); // 49Faqzd8jx

const password = generatePassword({
  symbols: 2,               // Resulting password must contain exactly two symbols.
  uppercase: { min: 1 },    // Resulting password must contain a minimum of 1 upperase character.
});
console.log(password); // b1yT6$jO`kvf

const uppercasePassword = generatePassword({
  length: 10,               // Length of the resulting password.
  digits: false,            // Resulting password must NOT contain any digits.
  symbols: false,           // Resulting password must NOT contain any symbols.
  lowercase: false,         // Resulting password must NOT contain any lowercase characters.
});
console.log(uppercasePassword); // IHDPPZRNPS

generatePin(length: number): string

Generate a random digit pin.

Examples:

generatePin(6); // 036919
generatePin(8); // 45958396

License

The MIT License (MIT). See LICENSE file.