Password Generator
unknown
javascript
a month ago
1.3 kB
1
Indexable
Never
//Random Password Generator function generatePassword(passwordLength, includeSmallLetters, includeCapitalLetters, includeNumbers, includeSpecialCharecters) { let allowedPassword = ""; let password = ""; allowedPassword += includeSmallLetters ? "abcdefghijklmnopqrstuvwxyz" : ""; allowedPassword += includeCapitalLetters ? "ABCDEFGHIJKLMNOPQRSTUVWXYZ" : ""; allowedPassword += includeNumbers ? "0123456789" : ""; allowedPassword += includeSpecialCharecters ? "!@#$%^&*()_+=/*-" : ""; if(!allowedPassword.length) { console.log(`You must select at least 1 set of charecters.`); } if(passwordLength == 0) { console.log(`Length of the password must be positive.`); } for(let i=0; i<passwordLength; i++) { rand = Math.floor(Math.random()*allowedPassword.length); password += allowedPassword.charAt(rand); } console.log(`Generated Password: ${password}`); } let passwordLength = 10; let includeSmallLetters = true; let includeCapitalLetters = true; let includeNumbers = true; let includeSpecialCharecters = true; generatePassword(passwordLength, includeSmallLetters, includeCapitalLetters, includeNumbers, includeSpecialCharecters);
Leave a Comment