Ad

In this Kata you will need to write a function that returns whether a password is strong or not.

Your code should return a Boolean of true if the provided password meets the following conditions

  1. password must be no less than 8 characters long
  2. password must have at least 1 capital letter
  3. password must have at least 1 number
  4. password must have at least 1 special character

for this Kata special characters are considered ( ! " # $ % & ' ( ) * + ' - . / ; : < > = or ?)

if the password doesn't meet these requirements return false.

function testPassword(password){
  var cap = false;
  var spec = false;
  var number = false;
  var temp;
  
  for(i=0;i<password.length;i++){
  temp = password[i].charCodeAt();
    if(temp > 32 && temp < 48){
      spec = true;
    } else if(temp > 57 && temp < 64){
      spec = true;
    }
  }
//check each digit and see if any are capital letters
for(i=0;i<password.length;i++){
  if(password.charCodeAt(i) > 64 && password.charCodeAt(i) < 91){
    cap = true;
  }
}

//see if the password is over 8 digits long
if(password.length > 7){
  number = true;
}
  
  //provide final answer
  if(cap && number && spec){
    return true;
  } else {
    return false;
  }

}