Minimal Strong Password Generation for JavaScript – sspg.js

Category: Javascript | March 25, 2025
Authorlingrottin
Last UpdateMarch 25, 2025
LicenseMIT
Views38 views
Minimal Strong Password Generation for JavaScript – sspg.js

sspg.js is a lightweight JavaScript library for generating strong passwords without sacrificing control.

You can define character sets, and choose between standard and cryptographically secure random number generation.

Features:

  • Generates strong passwords of a specified length.
  • Offers a compact string-based configuration format.
  • Provides both regular and cryptographically secure random generation.
  • Uses easy-to-remember character codes (e.g., `0` for digits, `a` for lowercase).
  • Includes escape characters for literal inclusion of special characters.

How to use it:

1. Install ‘sspg.js’ via NPM:

# NPM
$ npm install sspg

2. Import the gen or gens function:

import { gen, gens } from "sspg";

3. Generate a 12-character password with digits, lowercase, and uppercase letters. Configuration String Characters:

  • 0: Digits (0-9)
  • a: Lowercase letters (a-z)
  • A: Uppercase letters (A-Z)
  • - or _: The characters - and _
  • .: Special characters: !@#$%^&*,.;:/?+=
  • [ or ]: Bracket characters: ()[]{}<>|'”~
  • c: Escape character. The following character is added directly to the character set.
  • s: Use the cryptographically secure random number generator.
  • u: Use the standard (Math.random()) random number generator.
const password = gen("0aA", 12);
// 2hVwVKhi31v2
console.log(password);

4. Generate a 12-character cryptographically secure password:

const password = gens("0aA", 12);
// Example: PaSnA1r0CesB
console.log(password);

5. Available configs:

const password = gen({
  characters: string;
  safe?: boolean;
}, 12);

You Might Be Interested In:


Leave a Reply