UNPKG

password-generator-by-oran

Version:

Random password generator

20 lines (16 loc) 532 B
function generate(length = 10, specialChars = false) { let letters; if(!specialChars) letters = "0123456789acbdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; else letters = "0123456789acbdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+-="; let password =""; for(let i =1; i<= length; i++){ const index = Math.floor(Math.random() * letters.length); password+= letters[index]; } return password; } module.exports = { generate };