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
- password must be no less than 8 characters long
- password must have at least 1 capital letter
- password must have at least 1 number
- 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;
}
}
Test.assertEquals(testPassword("password"), false);
Test.assertEquals(testPassword("Pas$word1"), true);
Test.assertEquals(testPassword("WodT$m1"), false);