Password Check (Case Sensitive)
CODE :
import java.lang.*;
import java.util.*;
import java.util.regex.*;
class CheckPass{
public static String check(String password){
Scanner a = new Scanner(System.in);
String check;
int x=0;
Pattern sc = Pattern.compile("[^A-Za-z0-9 ]");
Matcher m1 = sc.matcher(password);
Pattern uc = Pattern.compile("[A-Z]");
Matcher m2 = uc.matcher(password);
Pattern lc = Pattern.compile("[a-z]");
Matcher m3 = lc.matcher(password);
Pattern dc = Pattern.compile("[0-9]");
Matcher m4 = dc.matcher(password);
if(password.length()>=8)
{
x=1;}
if(m1.find() && m2.find() && m3.find() && m4.find() && x==1)
{
check=password;
}
else
{ System.out.println("Password should must contain");
System.out.println("1.a Uppercase Letter");
System.out.println("2.a Lowercase Letter");
System.out.println("3.a Numerical value");
System.out.println("4.a Special character");
System.out.println("5.Password Must contain 8 letters");
System.out.print("Please enter Password : ");
String newpassword=a.next();
check=check(newpassword);
} return check;
}
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.print("Please Enter the Password : ");
String Password = sc.next();
Password = check(Password);
System.out.println("Password Saved Successfully");
System.out.println("The Saved Password is :"+Password);
}}
Inputs and Outputs :