Password validator project issue 


#1

Hi there guys and gals,

I am having an issue with this Password Validator project.

The validator doesn't validate the presence of upper/lower case letters when the password contains a special character.

Any advice?

function hasUppercase(input){
  for (var i = 0; i < input.length; i++){    
      if(input[i] === input[i].toUpperCase()) {
        return true;
      }   
  }
}

function hasLowercase(input){
  for (var j = 0; j < input.length; j++){    
      if(input[j] === input[j].toLowerCase()) {
        return true;
      }   
  }
}

function isLongEnough(input){
  if (input.length >= 8 ){
    return true;
  }
}

function hasSpecialCharacter(input){
  var specialCharacters = ['!', '@', '#', '$', '%', '^', '&', '*']; 
   
  for ( var k =0; k < input.length; k++){
        for (var l = 0; l < specialCharacters.length; l++){
        if (input[k] === specialCharacters[l]) {
          return true; 
}
  }
}
}
                            
function isPasswordValid(input){
  if (hasUppercase(input) === true && (hasLowercase(input) === true) && (isLongEnough(input) === true) && (hasSpecialCharacter(input)) === true) {
    console.log('Password is vaild');
  }
  if (hasUppercase(input) !== true){
    console.log('the password must have a capital letter');
  }
 if (hasLowercase(input) !== true){
    console.log('the password must have a lowercase letter');
  }
  if (isLongEnough(input) !== true){
    console.log('the password must be more than 8 characters');
  }
  if (hasSpecialCharacter(input) !== true){
    console.log('the password must contain a special char');
  }
}
                
isPasswordValid('KKLKJJH@');

Regards,

James


#2

Sorry, just seen that this issue has been posted multiple times. I will search the forums first next time!