| 22 | } |
| 23 | |
| 24 | function generatePassword(len, isLC, isUC, isNum, isSym){ |
| 25 | let charCodes = []; |
| 26 | if(isLC) |
| 27 | charCodes = LOWERCASE_CHAR_CODES; |
| 28 | if(isUC) |
| 29 | charCodes = charCodes.concat(UPPERCASE_CHAR_CODES); |
| 30 | if(isNum) |
| 31 | charCodes = charCodes.concat(NUMBER_CHAR_CODES); |
| 32 | if(isSym) |
| 33 | charCodes = charCodes.concat(SYMBOL_CHAR_CODES); |
| 34 | |
| 35 | const finalPassword = []; |
| 36 | for(let i = 0; i < len; i++){ |
| 37 | const randomCode = charCodes[Math.floor(Math.random() * charCodes.length)]; |
| 38 | finalPassword.push(String.fromCharCode(randomCode)); |
| 39 | } |
| 40 | |
| 41 | //if all of the checkbox are unchecked |
| 42 | if(charCodes.length === 0) |
| 43 | return `Select at least one option`; |
| 44 | |
| 45 | return finalPassword.join(''); //return string of array finalPassword |
| 46 | } |
| 47 | |
| 48 | function arrayLowToHigh(low, high){ |
| 49 | let array = []; |