JAVA Password Checker a Simple Password Strength Verifier P
JAVA
Password Checker - a Simple Password Strength Verifier Purpose: to provide an exercise using strings and chars and their associated methods. Computer security is an important topic, and many Web sites have minimum requirements for password formats, such as a minimum length or the requirement for using certain characters. For this assignment, you will create a Java program that will check submitted passwords for verification against minimum requirements. Do NOT use regular expressions, Pattern, or Matcher classes to solve this lab – use appropriate String, StringBuffer, and/or Character methods. You will receive a zero for this lab, otherwise.
Part 1 Create a PswdChecker class definition in a single file (PswdChecker.java) that has a single method:
public Boolean isValid(String Input)
This method will loop through the input String checking each character for the following rules: - Each character can be a letter a-z or A-Z, a numeric digit, or any of the following characters: ‘@’ (the “at” sign), ‘.’ (a “period”), ‘_’ (underscore), ‘-‘ (dash), ‘~’ (tilde), ‘#’ (“pound” sign), ‘!’ (exclamation point), ‘&’ (ampersand), or ‘$’ (dollar) - The input String must contain at least one non-letter character; that is, a character from the above list, not including a-z or A-Z.
- The input String cannot contain a space character (blank) or any character not in the first list above; it also cannot be an “empty” String. - The input String must be no less than 8 characters in length - The input String must contain at least one capitalized letter; that is, a character from the list, A-Z. This method will return a true value if the password meets all of the above criteria, otherwise it will return a false value.
Additionally, this program will print on the system console appropriate output (as shown at the end of this document) to log each verification, whether successful or unsuccessful. This log also will display the value of the password verified. This program will do not user input or other user output.
Part 2 Write another program, TestPswd.java, that will use the PswdChecker class to check passwords submitted by the user. Therefore, when you run TestPswd, your program creates a PswdChecker object that is used to verify passwords. This program will obtain user input, call the isValid() method passing the input String to it, and will display user output indicatingwhether the password is valid or not, depending on the result returned from the call to the isValid() method. This program only uses the GUI for input and output.
You will need to import javax.swing.JOptionPane and call JOptionPane.showInputDialog() to accept values from the user. Arguments to pass are: null, \"Please enter maximum table size (0 to quit):\", \"Multiplication Table Maker\", and JOptionPane.QUESTION_MESSAGE, in that order. The program terminates when the user enters a ‘q’. See the following example:
The JOptionPane.showInputDialog() method will return null if the user clicks the Cancel button. Use this knowledge to make your programs loop as long as the user clicks OK, no matter what is or is not entered as the password.
Use all inputs from the sample shown below. Yours should match.
Your lab should work with a variety of passwords, but use the input shown below for the captured output.
This must compile and be in copyable code! Thank you!
Solution
/********* Password Checker class ******************/
public class PswdChecker {
public Boolean isValid(String Input) {
int numOfSpecial = 0;
int numOfUpperLetters = 0;
int numOfLowerLetters = 0;
int numOfDigits = 0;
StringBuffer logger = new StringBuffer();
boolean isInvalidCharacter = false;
boolean isValidPswd = true;
logger.append(\"Password \\\"\").append(Input).append(\"\\\" is:\ \");
byte[] bytes = Input.getBytes();
for (byte tempByt : bytes) {
char tempChar = (char) tempByt;
if (tempChar ==\'&\' ||tempChar ==\'@\' ||tempChar ==\'#\' ||tempChar ==\'~\' ||tempChar ==\'.\' ||tempChar ==\'_\' ||tempChar ==\'-\'||tempChar ==\'$\'||tempChar==\'!\' ) {
numOfSpecial++;
}
else if (Character.isDigit(tempChar)) {
numOfDigits++;
}
else if (Character.isUpperCase(tempChar)) {
numOfUpperLetters++;
}
else if (Character.isLowerCase(tempChar)) {
numOfLowerLetters++;
}
else{
isInvalidCharacter = true;
}
}
if(isInvalidCharacter){
logger.append(\"Rejected : Invalid character(s) found\ \");
logger.append(\"must be only A-Z, a-z, 0-9, or . @ _ - ~ # ! & $\ \");
isValidPswd = false;
}
if(numOfLowerLetters==0){
logger.append(\"Rejected : Password must have at least one lowercase character!\ \");
isValidPswd = false;
}
if(numOfUpperLetters==0){
logger.append(\"Rejected : Password must have at least one upercase character!\ \");
isValidPswd = false;
}
if(numOfSpecial==0 && numOfDigits == 0){
logger.append(\"Rejected : Missing required character.\ \");
logger.append(\"must have at least one of 0-9 . @ _ - ~ # ! & $\ \");
isValidPswd = false;
}
if(Input.length()<8){
logger.append(\"Rejected : Password is too short.\ \");
logger.append(\"must be 8 or more characters.\ \");
}
System.out.println(logger.toString()+\"\ \");
return isValidPswd;
}
}
/****************************** Test Password and Main Class ************************/
import javax.swing.JOptionPane;
public class TestPswd {
public static void main(String[] args) {
String input=\"\";
for(;;){
input = JOptionPane.showInputDialog(null,\"Enter Password to check:\");
if(input == null){
input =\"\";
}
if(input.equals(\"q\")){
break;
}
PswdChecker pswdChecker = new PswdChecker();
Boolean isValid = pswdChecker.isValid(input);
if(isValid){
JOptionPane.showMessageDialog(null, \"Password is valid\");
}
if(!isValid){
JOptionPane.showMessageDialog(null, \"Password is NOT valid\");
}
}
}
}


