borisova936935

Untitled

Apr 3rd, 2022
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function passwordValidator(input) {
  2.     let password = input.shift();
  3.     for (let tokens of input) {
  4.       tokens = tokens.split(" ");
  5.       let currComm = tokens[0];
  6.       if (currComm == "Make" && tokens[1] == "Upper") {
  7.         let i = Number(tokens[2]);
  8.         let copy = password.split("");
  9.         if (i >= 0 && i < copy.length) {
  10.           let letter = password.charAt(i).toUpperCase();
  11.           password = password.replace(password.charAt(i), letter);
  12.           console.log(password);
  13.         }
  14.       }
  15.       if (currComm == "Make" && tokens[1] == "Lower") {
  16.         let index = +tokens[2];
  17.         let array = password.split("");
  18.         if (index >= 0 && index < array.length) {
  19.           let letter = password.charAt(index).toLowerCase();
  20.           password = password.replace(password.charAt(index), letter);
  21.           console.log(password);
  22.         }
  23.       }
  24.       if (currComm == "Insert") {
  25.         let index = Number(tokens[1]);
  26.         let char = tokens[2];
  27.         if (password[index] != undefined) {
  28.           let part1 = password.slice(0, index);
  29.           let part2 = password.slice(index);
  30.           password = part1 + char + part2;
  31.           console.log(password);
  32.         }
  33.       }
  34.       if (currComm == "Replace") {
  35.         let charLetter = tokens[1];
  36.         if (!password.includes(charLetter)) {
  37.           continue;
  38.         } else {
  39.           let char = Number(tokens[1].charCodeAt());
  40.           let value = Number(tokens[2]);
  41.           let sumChar = String.fromCharCode(char + value);
  42.           password = password.split(charLetter).join(sumChar);
  43.           console.log(password);
  44.         }
  45.       }
  46.       if (currComm == "Validation") {
  47.         let regexWhole = /^[A-Za-z0-9_]+$/g;
  48.         let regexUpper = /[A-Z]+/g;
  49.         let regexLower = /[a-z]+/g;
  50.         let regexDigits = /[0-9]+/g;
  51.         if (password.length < 8) {
  52.           console.log("Password must be at least 8 characters long!");
  53.         }
  54.         if (!regexWhole.test(password)) {
  55.           console.log("Password must consist only of letters, digits and _!");
  56.         }
  57.         if (!regexUpper.test(password)) {
  58.           console.log("Password must consist at least one uppercase letter!");
  59.         }
  60.         if (!regexLower.test(password)) {
  61.           console.log("Password must consist at least one lowercase letter!");
  62.         }
  63.         if (!regexDigits.test(password)) {
  64.           console.log("Password must consist at least one digit!");
  65.         }
  66.       }
  67.       if (currComm == "Complete") {
  68.         break;
  69.       }
  70.     }
  71.   }
Advertisement
Add Comment
Please, Sign In to add comment