vikkktor

Functions_passwordValidator

Oct 11th, 2021 (edited)
917
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function printResult(password) {
  2.     let passwordLength = password.length
  3.     let isValidPassword = true;
  4.  
  5.     let checkLength = (password) => {
  6.         return passwordLength
  7.     }
  8.     let checkContent = (password) => {
  9.         for (i = 0; i < passwordLength; i++) {
  10.             if (password[i].charCodeAt(0) < 48 || password[i].charCodeAt(0) > 122) {
  11.                 return false
  12.             }
  13.         }
  14.     }
  15.     let digitsCount = (password) => {
  16.         let digitCnt = 0;
  17.         for (i = 0; i < passwordLength; i++) {
  18.             if (password[i].charCodeAt(0) >= 48 && password[i].charCodeAt(0) <= 57) {
  19.                 digitCnt++
  20.             }
  21.         }
  22.         return digitCnt;
  23.     }
  24.  
  25.  
  26.     if (checkLength(password) < 6 && checkLength(password > 10)) {
  27.         console.log("Password must be between 6 and 10 characters")
  28.         isValidPassword = false
  29.     }
  30.  
  31.     if (checkContent(password) == false) {
  32.         console.log("Password must consist only of letters and digits")
  33.         isValidPassword = false
  34.     }
  35.  
  36.     if (digitsCount(password) < 2) {
  37.         console.log("Password must have at least 2 digits")
  38.         isValidPassword = false
  39.     }
  40.  
  41.     if (isValidPassword === true) {
  42.         console.log("Password is valid");
  43.     }
  44. }
  45.  
  46. printResult('MyPass123')
RAW Paste Data