Program to check the validity of a Password
Password checker program basically checks if the password is valid or not based on password policies mention below:
- Password should not contain any space.
- Password should contain at least one digit(0-9).
- Password length should be between 8 to 15 characters.
- Password should contain at least one lowercase letter(a-z).
- Password should contain at least one uppercase letter(A-Z).
- Password should contain at least one special character ( @, #, %, &, !, $, etc….).
Input: GeeksForGeeks Output: Invalid Password! This input contains lowercase as well as uppercase letters but does not contain digits and special characters. Input: Geek$ForGeeks7 Output: Valid Password This input satisfies all password policies mentioned above.
In this program,
- we are using String contains () method to check the passwords. This method accepts a CharSequence as an argument and returns true if the argument is present in a string otherwise returns false.
- Firstly the length of the password has to be checked then whether it contains uppercase, lowercase, digits and special characters.
- If all of them are present then the method isValid(String password) returns true.
Below is the implementation of the above approach:
Invalid Password!!! Valid Password
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.