@arraypress/password
v1.0.0
Published
Cryptographically secure password generation and strength analysis — configurable charsets, pronounceable passwords, entropy calculation.
Maintainers
Readme
@arraypress/password
Cryptographically secure password generation and strength analysis. Configurable charsets, pronounceable passwords, entropy calculation.
All generation functions use crypto.getRandomValues() for secure randomness. Works in browsers, Node.js 19+, Cloudflare Workers, Deno, and Bun. Zero dependencies.
Install
npm install @arraypress/passwordFunctions
generate(options?)
Generate a secure password.
import { generate } from '@arraypress/password';
generate()
// => 'K7#mN9$pQ2@vX8!z'
generate({ length: 12, symbols: false })
// => 'K7mN9pQ2vX8z'
generate({ length: 20, charset: '0123456789ABCDEF' })
// => 'A3F90BCE172D64A0B531'
generate({ length: 16, exclude: ['0', 'O', '1', 'l'] })
// => 'K7#mN9$pQ2@vX8!z'Options: length (4-128), uppercase, lowercase, numbers, symbols (all default true), charset (custom override), exclude (chars to remove).
generateMultiple(count?, options?)
Generate multiple passwords.
import { generateMultiple } from '@arraypress/password';
generateMultiple(3, { length: 12, symbols: false })
// => ['K7mN9pQ2vX8z', 'F3rL5wM1nP4y', 'B8kG2jS6eA9c']pronounceable(options?)
Generate a pronounceable password using alternating consonants and vowels.
import { pronounceable } from '@arraypress/password';
pronounceable()
// => 'mebakitulo47'
pronounceable({ length: 10, capitalize: true })
// => 'Kolivesu23'
pronounceable({ length: 8, numbers: false })
// => 'mobalife'analyze(password)
Analyze password strength with entropy calculation and improvement suggestions.
import { analyze, STRENGTH } from '@arraypress/password';
analyze('password123')
// => {
// length: 11,
// hasUppercase: false, hasLowercase: true,
// hasNumbers: true, hasSymbols: false,
// charsetSize: 36, entropy: 52.4,
// strength: 'fair', label: 'Fair',
// diversity: 0.5,
// suggestions: ['Add uppercase letters', 'Add special symbols']
// }
const result = analyze('K7#mN9$pQ2@vX8!z');
result.strength === STRENGTH.VERY_STRONG // true
result.entropy // 105.2
result.suggestions // []Strength levels: very_weak (<30 bits), weak (30-40), fair (40-60), strong (60-80), very_strong (80+).
entropy(length, charsetSize)
Calculate entropy in bits.
import { entropy } from '@arraypress/password';
entropy(16, 95) // ~105.3 bits (full printable ASCII)
entropy(8, 26) // ~37.6 bits (lowercase only)
entropy(4, 10) // ~13.3 bits (4-digit PIN)charsets
Access built-in character sets.
import { charsets } from '@arraypress/password';
charsets.uppercase // 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
charsets.symbols // '!@#$%^&*()_+-=[]{}|;:,.<>?'
charsets.alnum // letters + numbers (62 chars)
charsets.all // letters + numbers + symbols (95 chars)License
MIT
