@masterdineshchoudhary/secure-password-generator
v1.0.1
Published
Generate cryptographically secure random passwords
Downloads
64
Maintainers
Readme
secure-password-generator
Generate cryptographically secure random passwords using Node.js crypto module.
Installation
npm install secure-password-generatorUsage
const generatePassword = require("secure-password-generator");
// Generate a 12-character password with all character types
const password = generatePassword();
console.log(password); // e.g. "aB3$xK9!mQ2@"
// Customize length
const longPassword = generatePassword({ length: 24 });
// Disable certain character types
const numbersOnly = generatePassword({
uppercase: false,
lowercase: false,
symbols: false,
length: 8
});
// e.g. "48291573"API
generatePassword([options])
options
| Option | Type | Default | Description |
|-------------|-----------|---------|---------------------------------|
| length | number | 12 | Length of the generated password |
| uppercase | boolean | true | Include uppercase letters (A-Z) |
| lowercase | boolean | true | Include lowercase letters (a-z) |
| numbers | boolean | true | Include numbers (0-9) |
| symbols | boolean | true | Include symbols (!@#$%^&*()_-+=[]{}|;:',.<>?/~`) |
Returns
string — the generated password.
Throws
- If
lengthis not a positive integer. - If no character sets are selected.
Security
This package uses crypto.randomBytes with rejection sampling to ensure unbiased, cryptographically secure random passwords.
License
MIT
