A Java program to constraint your password with letter,special character,number for varification

import java.util.Scanner;
public class Password3 {

public static void main(String[] args) {
    int min =8;
    int max=16;
    int digit=0;
    int special=0;
    int upCase=0;
    int loCase=0;
    String password;
    Scanner sc = new Scanner(System.in);
    System.out.println(" Enter Your Password:");
        password = sc.nextLine();
        for(int i =0;i<password.length();i++){
		if(password.length()>=min&&password.length()<=max){
            char c = password.charAt(i);
            if(Character.isUpperCase(c)){
                upCase++;
            }
            if(Character.isLowerCase(c)){
                loCase++;
            }
            if(Character.isDigit(c)){
                digit++;
            }
            if(c>=33&&c<=46||c==64){
                special++;
            }
		}
		}
        if(special>=1&&loCase>=1&&upCase>=1&&digit>=1){
            System.out.println(" Password is perfectly match you can procced:" +password);
		}

else{
	if(password.length()<min){
		System.out.println("1. Password must be atleat "+min+" characters:");
	}
	if(password.length()>max){
		System.out.println("2. Password must be less than "+max+" characters:");
	}
	if(special<1){
		System.out.println("3. You need atleast one special chracter:");
	}
	if(digit<1){
		System.out.println("4. You need atleast one digit:");
	}
	if(upCase<1){
        System.out.println("5. You need atleast one upper case:");
	}
		if(loCase<1){
        System.out.println("6. You need atleast one lower case:");
          }
        }
	}
}

View all posts

Follow My Blog

Get new content delivered directly to your inbox.

Published by temamhashim

This is Temam Hashim certified Software Engineer from top leading University with highest score with full capablity of various top leading programming language as a software Engineer and ability to deal with logic and mathimatical problem.

Leave a comment

Design a site like this with WordPress.com
Get started