1export interface GeneratorOptions {2 length: number;3 includeUppercase: boolean;4 includeLowercase: boolean;5 includeNumbers: boolean;6 includeSymbols: boolean;7}89101112export function generatePassword(options: Partial<GeneratorOptions> = {}): string {13 const {14 length = 20,15 includeUppercase = true,16 includeLowercase = true,17 includeNumbers = true,18 includeSymbols = true,19 } = options;2021 let chars = "";22 if (includeLowercase) chars += "abcdefghijklmnopqrstuvwxyz";23 if (includeUppercase) chars += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";24 if (includeNumbers) chars += "0123456789";25 if (includeSymbols) chars += "!@#$%^&*";2627 if (chars.length === 0) chars = "abcdefghijklmnopqrstuvwxyz";2829 const array = crypto.getRandomValues(new Uint32Array(length));30 let password = "";31 for (let i = 0; i < length; i++) {32 password += chars[array[i] % chars.length];33 }34 return password;35}