MCPcopy Create free account
hub / github.com/AyushSaini00/60minuteJavaScript / generatePassword

Function generatePassword

Password-Generator/app.js:24–46  ·  view source on GitHub ↗
(len, isLC, isUC, isNum, isSym)

Source from the content-addressed store, hash-verified

22}
23
24function 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
48function arrayLowToHigh(low, high){
49 let array = [];

Callers 1

updateUIFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected