1.2.0 • Published 10 months ago

random-password-typescript v1.2.0

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

random-password-typescript

This library is a type-safe, secure, and customizable password generator for TypeScript users. It leverages TypeScript’s strict typing system, making password generation flexible, predictable, and tailored to your needs—whether you're after a basic password or something more complex.

Note: This library uses Node.js’s crypto module, so it won’t run in the browser. If you need it in a web app, consider creating an API route.

Check it out on GitHub!

Prerequisites

You'll need:

  • Node.js (version 14.x or higher)
  • TypeScript (if you're working directly with TypeScript)

Installation

Install via npm:

npm install random-password-typescript

Usage

Import the generatePassword function and get started:

import { generatePassword } from "random-password-typescript";

// Simple password generation
const password = generatePassword(1);
console.log(password); // Randomly generated password

Generating Multiple Passwords

The first argument is a number representing how many passwords you want, and the second is an object with the customization options.

const passwords = generatePassword(5, {
  length: 12,
  useNumbers: true,
  useSymbols: true,
  mustHave: ["@", "1"],
  startsWith: "MyP@ss",
  endsWith: "!",
});
console.log(passwords); // Array of 5 passwords

Options

Here’s a breakdown of the available options to tweak your password generation:

OptionTypeDefaultDescription
lengthnumberundefinedSets the exact password length.
randomLengthbooleanfalseIf true, generates a random length within a specified range.
minLengthnumber8Minimum password length (if randomLength is true).
maxLengthnumber16Maximum password length (if randomLength is true).
lengthRange[number, number]undefinedDefines a range for random length generation.
useNumbersbooleantrueInclude numbers in the password.
useSymbolsbooleantrueInclude symbols in the password.
lowercaseOnlybooleanfalseOnly lowercase characters.
uppercaseOnlybooleanfalseOnly uppercase characters.
excludeSimilarCharactersbooleanfalseExcludes visually similar characters like oO0, iIl1.
excludeWordsstring[][]Exclude specific words from appearing in the password.
excludeCharsstring[][]Exclude specific characters from the password.
mustHavestring[][]Characters that must appear in the password.
startsWithstring""Specifies a string the password must start with.
endsWithstring""Specifies a string the password must end with.
patternstring""Pattern for password generation. Use L for lowercase, U for uppercase, and D for digits.

That’s it! Play around with the options and generate passwords tailored to your exact needs. Feel free to check out the project on GitHub for more details.

1.2.0

10 months ago

1.1.1

10 months ago

1.1.0

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago