Password Generator
unknown
javascript
a year ago
1.3 kB
28
Indexable
//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);Editor is loading...
Leave a Comment