Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main{
- public static String checkPassword(String password){
- boolean hasUpperCase = false;
- boolean hasLowerCase = false;
- boolean hasDigit = false;
- boolean hasSpecialChar = false;
- String specialChars = "@$^~";
- if(password.length()<8){
- return "Password must be atleast 8 characters";
- }
- for(char c : password.toCharArray()){
- if(Character.isUpperCase(c)){
- hasUpperCase = true;
- }else if(Character.isLowerCase(c)){
- hasLowerCase = true;
- }else if(Character.isDigit(c)){
- hasDigit = true;
- }else if(specialChars.indexOf(c)>=0){
- hasSpecialChar = true;
- }
- }
- if(hasUpperCase && hasLowerCase && hasDigit && hasSpecialChar)
- return "Strong Password";
- else if((hasUpperCase && hasLowerCase && hasDigit)||(hasLowerCase && hasDigit && hasSpecialChar)||(hasDigit && hasSpecialChar && hasUpperCase)||(hasSpecialChar && hasUpperCase && hasLowerCase))
- return "Medium Password";
- else
- return "Weak Password";
- }
- public static void main(String[] args){
- Scanner read = new Scanner(System.in);
- System.out.println("Enter Password:");
- String password = read.nextLine();
- System.out.println(checkPassword(password));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement