Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function passwordValidator(input) {
- let password = input.shift();
- for (let tokens of input) {
- tokens = tokens.split(" ");
- let currComm = tokens[0];
- if (currComm == "Make" && tokens[1] == "Upper") {
- let i = Number(tokens[2]);
- let copy = password.split("");
- if (i >= 0 && i < copy.length) {
- let letter = password.charAt(i).toUpperCase();
- password = password.replace(password.charAt(i), letter);
- console.log(password);
- }
- }
- if (currComm == "Make" && tokens[1] == "Lower") {
- let index = +tokens[2];
- let array = password.split("");
- if (index >= 0 && index < array.length) {
- let letter = password.charAt(index).toLowerCase();
- password = password.replace(password.charAt(index), letter);
- console.log(password);
- }
- }
- if (currComm == "Insert") {
- let index = Number(tokens[1]);
- let char = tokens[2];
- if (password[index] != undefined) {
- let part1 = password.slice(0, index);
- let part2 = password.slice(index);
- password = part1 + char + part2;
- console.log(password);
- }
- }
- if (currComm == "Replace") {
- let charLetter = tokens[1];
- if (!password.includes(charLetter)) {
- continue;
- } else {
- let char = Number(tokens[1].charCodeAt());
- let value = Number(tokens[2]);
- let sumChar = String.fromCharCode(char + value);
- password = password.split(charLetter).join(sumChar);
- console.log(password);
- }
- }
- if (currComm == "Validation") {
- let regexWhole = /^[A-Za-z0-9_]+$/g;
- let regexUpper = /[A-Z]+/g;
- let regexLower = /[a-z]+/g;
- let regexDigits = /[0-9]+/g;
- if (password.length < 8) {
- console.log("Password must be at least 8 characters long!");
- }
- if (!regexWhole.test(password)) {
- console.log("Password must consist only of letters, digits and _!");
- }
- if (!regexUpper.test(password)) {
- console.log("Password must consist at least one uppercase letter!");
- }
- if (!regexLower.test(password)) {
- console.log("Password must consist at least one lowercase letter!");
- }
- if (!regexDigits.test(password)) {
- console.log("Password must consist at least one digit!");
- }
- }
- if (currComm == "Complete") {
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment