export interface GeneratorOptions { length: number; includeUppercase: boolean; includeLowercase: boolean; includeNumbers: boolean; includeSymbols: boolean; } /** * Generate a cryptographically random password. */ export function generatePassword(options: Partial = {}): string { const { length = 20, includeUppercase = true, includeLowercase = true, includeNumbers = true, includeSymbols = true, } = options; let chars = ""; if (includeLowercase) chars += "abcdefghijklmnopqrstuvwxyz"; if (includeUppercase) chars += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; if (includeNumbers) chars += "0123456789"; if (includeSymbols) chars += "!@#$%^&*"; if (chars.length === 0) chars = "abcdefghijklmnopqrstuvwxyz"; const array = crypto.getRandomValues(new Uint32Array(length)); let password = ""; for (let i = 0; i < length; i++) { password += chars[array[i] % chars.length]; } return password; }