Password Validator
We are going to write a program to make sure that a password is tricky so that it cannot be guessed too easily. It will check multiple factors of an entered password and will report back to the user if their password meets a set of rules.
The rules for our password validator are:
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.
2)
The isPasswordValid function will run each function we make in the upcoming steps.
Build the first condition:
A function that verifies the password has an uppercase letter. Declare a function named hasUppercase that takes one parameter named input.hasUpperCase(input){
}
3) The purpose of hasUppercase is to determine whether a password has an uppercase letter or not. If so, it should return true. Inside the hasUppercase function, you’ll need to check every letter of the password to see if it is an uppercase letter. In a future step, you’ll pass in the password to this function as the input parameter. To accomplish this rule, write a for loop that iterates through each letter of the input parameter inside the hasUppercase function.
Inside the for loop, write an if statement that checks if each input letter is equal to the uppercase version of itself. You can utilize the JavaScript function toUpperCase to transform a letter to its uppercase version. If the input does have an uppercase letter, return true. If not, don’t return anything.