Sunday, October 26, 2014

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!






















No comments:

Post a Comment