Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2014
    Posts
    1
    Rep Power
    0

    Default Password Rule using Wrapper Class

    Hello!

    This is my first post here, I hope I am not posting it in the wrong section.

    I have to use wrapper class for this assignment. I need to know if my code is more like object oriented or not and am I using the wrapper class properly here? Let me know if I can make this code better.

    I also need to know if I can mask this password input (STRING) using NetBeans/Eclipse IDE?

    Password rule is as followed : Length of Password 8-12, with no special characters, including minimum one uppercase letter, and only one numeric value.

    Here is the code :

    Java Code:
    import java.util.Scanner;
    public class Assignment1 
    {
        private static String password=null;
        
        private static void password_input()
        {
            
            Scanner input = new Scanner(System.in);
            password = input.nextLine();
            
        }
        
       private static void length_checking()
       {
           
           int x;
           x = password.length();
           if(x<8)
           {
               display();
               System.out.println("-Length of Password is "+x+", which is "+(8-x)+" short than the minimum limit 8! ");
               specialcharacters_checking();
               only_one_numericvalue_checking();
               minimum_one_uppercase_letter();
           }
           else if(x>12)
           {
                 display();
                 System.out.println("-Length of Password is "+x+", which is "+(x-12)+" long than the maximum limit 12! "); 
                 specialcharacters_checking();
                 only_one_numericvalue_checking();
                 minimum_one_uppercase_letter();
                 
           }
           else 
           {
           display();
           specialcharacters_checking();
           only_one_numericvalue_checking();
           minimum_one_uppercase_letter();
           
           }
        }
       
       
       
          private static void specialcharacters_checking()
       {
           boolean check1;
           int i=0,check2=0;
           for(int x=0;x<password.length();x++)
            {
                
           check1=Character.isLetterOrDigit(password.charAt(x));
           
           if(check1==false)
               
                {
                    
                    check2=1;               
                    
                }             
            }
           if(check2==1)
               System.out.println("-It has the following special characters which are not allowed :");
           for(int x=0;x<password.length();x++)
            {
                
           check1=Character.isLetterOrDigit(password.charAt(x));
           
           if(check1==false)
               
                {
                    
                    System.out.println(password.charAt(x));
                    
                }
                    
            }
           
       }
          
      
          
          
          private static void only_one_numericvalue_checking()
          {
              boolean check;
              int i=0;
              for(int x=0;x<password.length();x++)
              {
                 check=Character.isDigit(password.charAt(x)); 
                 if(check==true)
                 {
                 i++;
                 if(i>1)
                 {
                     System.out.println("-It has more than 1 numeric value!");
                     break;
                 }
                            
                 }
                 
                 
              }
              if(i==0)
                 {
                     System.out.println("-It has no numeric value!");
                 }
          }
          
          
          private static void minimum_one_uppercase_letter()
          {
               boolean check;
              int i=0;
              for(int x=0;x<password.length();x++)
              {
                 check=Character.isUpperCase(password.charAt(x)); 
                 if(check==true)
                 {
                 i++;          
                 }          
                 
              }
              if(i==0)
                 {
                     System.out.println("-It has no uppercase LETTER!");
                     
                 }
              
             
             
          }
          
        private static void display()
        {
            System.out.println("Password entered is : "+password);
        }
        
       
        
    
        public static void main(String[] args) 
        {
            System.out.println("\t\t\t\t****** ||Registration|| ****** \n Length of Password 8-12, with no special characters, including minimum one uppercase letter, and only one numeric value.\n Enter your password : ");
            password_input();
            length_checking();
            
            
        }
        
    }
    Thanks in advance!

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Password Rule using Wrapper Class

    It does not appear to me like you are using any wrapper class. You are just creating methods of the main class to validate the password.
    A wrapper class is one which usually contains an instance of a class which does mostly what you want. You then override or intercept method
    calls to enforce your own invariants (length of password, character classes allowed, etc) on the supplied password and then when
    appropriate, pass them to the wrapped instance. I do not know what class you are supposed to be wrapping but there is a JPasswordField class that prompts for passwords and also hides the user input.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Wrapper Class Java -- Creating a Password Help?
    By oneorderja in forum JCreator
    Replies: 0
    Last Post: 10-16-2012, 09:07 PM
  2. Need help with java wrapper class.
    By zeal3 in forum New To Java
    Replies: 1
    Last Post: 10-07-2009, 07:59 AM
  3. Yet another Wrapper Class confused guy.
    By JAdeline in forum New To Java
    Replies: 2
    Last Post: 08-15-2008, 05:04 AM
  4. Wrapper Class
    By haiforhussain in forum New To Java
    Replies: 6
    Last Post: 06-24-2008, 09:08 AM
  5. problem in wrapper class
    By binoympappachen in forum New To Java
    Replies: 4
    Last Post: 12-13-2007, 01:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •