Pasword validator


#1

HI. CAN ANYONE HELP WITH THIS PROJECT ? THE RUSULTS ARE : The password needs a capital letter. AND DOESN'T MENTION : Password needs to be longer. OR : Password is missing a special character . AND WHEN I TEST WITH UPPER CASE : isPasswordValid('BLUE'); SHOWS ME The password is valid
WHAT A MESS !!!!!!
function isPasswordValid(input){
if(hasUppercase(input)) {
console.log('The password is valid');
return true;
}
if(!hasUppercase(input)) {
console.log('The password needs a capital letter');
return false;
}
if(!hasLowercase(input)){
console.log('Password needs a lowercase letter');
}
if(hasUppercase(input) && hasLowercase(input)) {
console.log('Password is valid');
}
if(!isLongEnough(input)) {
console.long('Password needs to be longer');
}

     if(hasUppercase(input) && hasLowercase(input) && isLongEnough(input)) {
       console.log('Password is valid');
     }

     if(!hasSpecialCharacter(input)){
       console.log('Password is missing a special character');
       return false;
     }
       if(hasSpecialCharacter(input) && hasLowercase(input) && hasUppercase(input) && isLongEnough(input)){
       console.log('The password is valid');
       return true;

     }

}

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

function hasLowercase(input){
for(var i=0; i<input.lenght; i++) {
if(input[i] === input[i].toLowerCase()) {
return true;
}
}
}
function isLongEnough(input){
if(input.length >= 8) {
return true;
}
}
function hasSpecialCharacter(input){
var specialCharacters = ['!', '@','#','$','%','^','&', '*'];
for(var i=0; 0<input.length; i++) {
for(var j=0; 0<specialCharacters.length; j++){
if(input[i] === specialCharacters[j]);
return true;
}
}
}
isPasswordValid('blue');


#2

I'm sorry, but can you please explain your issue a little more clearly? It would really help us out.
Thanks :slight_smile:


#3

I am new to js and codeacademy .
We are going to write a program to make sure that a password is complex so that it cannot be easily guessed. Our password validator will check multiple aspects of a potential password and will report back to the user if their password meets a set of rules.

The rules for our password validator are:

Has at least one uppercase letter
Has at least one lowercase letter
Is at least 8 characters long
Has at least one special character
We can utilize functions to check for each of these requirements, then create a function to validate a user's password.

This program will be split into 5 functions:

A function that verifies the password has an uppercase letter.
A function that verifies the password has a lowercase letter.
A function that verifies the password is at least 8 characters
A function that verifies the password has a special character.
A function that reports to the user if their password is complex enough, and if not, tells them what they are missing.
Let's begin with the last function so that you can see your results as you progress through this project.