Write a program which validates a users password based on th

Write a program which validates a user\'s password based on the following properties, (each properties has to be in separate method)

java language

1. must be at least 10 characters long

2. must have at least 3 digits

3. must have at least 7 letters

4. must have at least 3 uppercase letters

5. must have at least 2 non-alphanumeric characters

Solution

PasswordCheckerSize10.java

import java.util.Scanner;

public class PasswordCheckerSize10 {

   public static void main(String[] args) {
       //Declaring variable
       String str=null;
       boolean bool1;
      
       //Scanner object is used to get the inputs entered by the user
   Scanner sc=new Scanner(System.in);
  
   //Creating SimpleWriter Class Object
       SimpleWriter out = new SimpleWriter();
      
      
       while(true)
       {
           //getting the String entered by the user
           System.out.print(\"Enter String :\");
           str=sc.next();
          
           /* Checking whether the string length is greater than 10 or not
           * If not,Display Error message
           */
           if(!checkSize(str))
           {
               //Displaying error message
               System.out.println(\"::Invalid Password. Password size must be atleast 10::\");
               continue;
           }
           /* Checking whether the string contains atleast 3 digits or not
           * If not ,Display error message
           */
           else if(contains3Digits(str)==0 || contains3Digits(str)<3 )
           {
               //Displaying error message
               System.out.println(\"::Invalid Password. Password must contains atleast 3 digits ::\");
               continue;
           }  
           /* checking whether the string contains atleast 7 letters
           * If not,display error message
           */
           else if(!contains7Letters(str))
           {
               //Displaying error message
               System.out.println(\"::Invalid Password. Password must contains atleast 7 Letters ::\");
               continue;
           }
           /* Checking whether the string contains 3 uppercase letters or not
           * If not,display error message
           */
           else if(!containsUpperCase(str))
           {
               //Displaying error message
               System.out.println(\"::Invalid Password. Password must contains atleast 3 UpperCase Letters ::\");
               continue;
           }
           /* checking whether the string contains atleast 2 non-alphanumeric characters or not
           * If not,display error message
           */
           else if(!containsAlphanumeric(str))
           {
               //Displaying error message
               System.out.println(\"::Invalid Password. Password must contains atleast 2 Non-alphanumeric Characters ::\");
               continue;
           }
           else
           {
               //if all the properties satisfied .displaying success message
               System.out.println(\":: Valid Password ::\");
               break;
           }
       }
      
   }

   //this method is used to Check whether the string contains non-alphanumeric charcaters or not
   private static boolean containsAlphanumeric(String str) {
       int count=0;
for(int i=0;i<str.length();i++)
{
   if(!(Character.isUpperCase(str.charAt(i))) || !(Character.isLowerCase(str.charAt(i))) || !(Character.isDigit(str.charAt(i))))
   {
       //Counting the number of non-alpha numeric characters
       count++;
   }
   if(count>=2)
       return false;
   else
       return true;
}
       return false;
   }

   /* This method is used to check whether the string
   * contains atleast 3 upper case letters or not
   */
   private static boolean containsUpperCase(String str) {
       boolean upper=false;
       int count=0;
       for(int i=0;i<str.length();i++)
       {
           if((Character.isUpperCase(str.charAt(i))))
           {
               upper=true;
               //Counting the number of uppercase letters
               count++;
           }  
       }
       if(count>=3)
           return true;
       else
           return false;
   }

   /*
   * This method is used to check whether the string contains atleast 7 charcaters or not.
   */
   private static boolean contains7Letters(String str) {
       boolean upper=false,lower=false;
       int count=0;
       for(int i=0;i<str.length();i++)
       {
       if((Character.isUpperCase(str.charAt(i))))
       {
           upper=true;
           //counting the number of upper case letters
           count++;
       }  
       //Checking whether the password contains an lower case letter or not
           if((Character.isLowerCase(str.charAt(i))))
           {
               lower=true;
               count++;
           }
       }
       if(count>=7)
           return true;
       else
           return false;
   }

   /* this method is used to check whether the
   * string contains atleast 3 digits or not
   */
   private static int contains3Digits(String str) {
       boolean digit=false;
       int count=0;
       for(int i=0;i<str.length();i++)
       {
           //Checking whether the password contains an single digit or not
           if((Character.isDigit(str.charAt(i))))
           {
               digit=true;
                 
               //Counting the number of digits
               count++;
           }          
       }
  
       return count;
   }

   /*
   * This method is used to calculate the length of the string
   */
   private static boolean checkSize(String str) {
       if(str.length()<10)
       return false;
       else
       return true;
   }

}

________________________________

Output:

Enter String :kane
::Invalid Password. Password size must be atleast 10::
Enter String :kane1234567
::Invalid Password. Password must contains atleast 7 Letters ::
Enter String :kanewilliams
::Invalid Password. Password must contains atleast 3 digits ::
Enter String :kanewilliams123
::Invalid Password. Password must contains atleast 3 UpperCase Letters ::
Enter String :KANewilliams123
:: Valid Password ::

_____________Thank You

Write a program which validates a user\'s password based on the following properties, (each properties has to be in separate method) java language 1. must be at
Write a program which validates a user\'s password based on the following properties, (each properties has to be in separate method) java language 1. must be at
Write a program which validates a user\'s password based on the following properties, (each properties has to be in separate method) java language 1. must be at
Write a program which validates a user\'s password based on the following properties, (each properties has to be in separate method) java language 1. must be at

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site