generatePassword
(options?: PasswordOptions) => string[]Generate secure passwords with customizable character sets. Guarantees at least one character from each enabled class (uppercase, lowercase, digits, symbols) using Fisher-Yates shuffle for unbiased placement. Quotes are excluded from default symbols for shell/SQL safety.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
length | number | 16 | Length of each password |
count | number | 1 | Number of passwords to generate |
uppercase | boolean | true | Include uppercase letters A-Z |
lowercase | boolean | true | Include lowercase letters a-z |
numbers | boolean | true | Include digits 0-9 |
symbols | boolean | true | Include special characters |
customSymbols | string | — | Custom special characters (overrides default set) |
minEntropy | number | — | Minimum entropy bits required (throws if config too weak) |
Returns
string[] — Array of generated passwords
Example
import { generatePassword } from "@bturkis/keygen";
// Default: 16 chars, all character classes
const [password] = generatePassword();
// No symbols, shorter
const simple = generatePassword({ length: 12, symbols: false });
// Custom special characters
const custom = generatePassword({ customSymbols: "!@#$" });
// Bulk generation with entropy enforcement
const bulk = generatePassword({
length: 20,
count: 100,
minEntropy: 128,
});💡 Throws an error if the configured length and character sets produce fewer entropy bits than minEntropy.