/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package hw3; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * * @author */ public class Hw3 { /** * @param args the command line arguments */ public static void main(String[] args) { //instructions System.out.print("The password must contain 8 characters, at least 1 number, 1 upper case letter, 1 lower case letter, and a special character\n"); //inputs Scanner input = new Scanner(System.in); System.out.print("Please enter a Password: "); String password = input.next(); input.close(); //condition if (valid(password)) { System.out.println("The password is valid "); } else { System.out.println("The password is Invalid."); } } //method public static boolean valid(String password) { //condition if (password.length() < 8) { return false; } else { // intializing variables inside char n; //String specialC ="!@#$%^&*_-"; boolean lower_Case = true; boolean upper_Case = true; boolean letter = true; boolean digit = true; boolean special_C = true; boolean result = true; for (int count = 0; count < password.length(); count++) { n = password.charAt(count); if (Character.isLowerCase(n)) { lower_Case = true; break; } else { System.out.print("! Missing a Lower Case letter"); } if (Character.isUpperCase(n)) { upper_Case = true; break; } else { System.out.print("! Missing an Upper case letter"); } if (Character.isLetter(n)) { letter = true; } else { System.out.print("! Missing a Letter"); break; } if (Character.isDigit(n)) { digit = true; } else { System.out.print("! Missing a Digit"); break; } String str = "!@#$%^&*_-"; if (password.equals(str)) { special_C = true; } else { System.out.print("! Missing a Special Charater "); } break; } result = lower_Case && upper_Case && letter && digit && special_C; return result; // } result = lower_Case && upper_Case && letter && digit && special_C; return result; // // } } }