Java program with wrapper classes I assume Write the followi

Java program with wrapper classes (I assume): Write the following program:

A program that checks a text file of passwords and verifies the passwords follow the rules below.

#1 Write a class called PasswordInformation, PasswordInformation class should have private fields for:

a. minimum password length - minimum password length is 4

b. maximum password length - maximum password length is 8

c. minimum number of uppercase letters - minimum uppercase letters length is 1

d. minimum number of digits - minimum number of digits is 1

Write a class called PasswordVerifier, PasswordVerifier should have the following methods:

a. Constructor that takes a PasswordInformation object.

b. CheckPassword which takes a String password and returns a String representing the validation results. The String should contain P\'s and F\'s based on which conditions pass or fail.

c. Write a class that uses PasswordInformation and PasswordVerifier. The class should read a text file containig a series of passwords (maximum 3 per line separated by spaces) and should output a text file containing the password specifications followed by the passwords and the validation results.

Examples:

Text file containing the following:

besting3 Ballfalls Mello5    W1o

Output example:

Password Information:

Minimum password length: 4

Maximum password length: 8

minimum number of uppercase letters: 1

minimum number of numbers : 1

P = Pass, F = False

besting3 PPFP

Mello5       PPPP

Ballfalls PFPF

M1o         FPPP

Solution

PasswordInformation.java

public class PasswordInformation {

  

private int minLength;

private int maxLength;

private int minUpperCase;

private int minDigit;

  

   public PasswordInformation()

   {

       this.minLength = 4;

       this.maxLength = 8;

       this.minUpperCase = 1;

       this.minDigit = 1;

   }

  

   public String validateMinLength(String input)

   {

       return input.length() >= minLength ? \"P\" : \"F\";

   }

  

   public String validateMaxLength(String input)

   {

       return input.length() <= maxLength ? \"P\" : \"F\";

   }

  

   public String validateMinUpperCase(String input)

   {

       return !input.equals(input.toLowerCase()) ? \"P\" : \"F\";

   }

  

   public String validateMinDigit(String input)

   {

       return input.matches(\".*\\\\d+.*\") ? \"P\" : \"F\";

   }

}

PasswordVerifier.java

public class PasswordVerifier {

  

   private PasswordInformation passwordInformation;

  

   public PasswordVerifier(PasswordInformation passwordInformation)

   {

       this.passwordInformation = passwordInformation;

   }

  

   public String checkPassword(String input)

   {

       String output = \"\";

       output += passwordInformation.validateMinLength(input);

       output += passwordInformation.validateMaxLength(input);

       output += passwordInformation.validateMinUpperCase(input);

       output += passwordInformation.validateMinDigit(input);

       return output;      

   }

}

PasswordVerifierTester.java

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.OutputStreamWriter;

public class PasswordVerifierTester {

  

   public static void main(String args[]) throws IOException

   {

       BufferedReader br = readFile();

       BufferedWriter bw = writeFile();

       String line = null;

       PasswordInformation passwordInformation = new PasswordInformation();

       PasswordVerifier passwordVerifier = new PasswordVerifier(passwordInformation);

       while( (line = br.readLine())!= null ) {

      String [] passwords = line.split(\"\\\\s+\");

      for(String password : passwords)

      {

         String output = passwordVerifier.checkPassword(password);

         bw.write(password + \" \" + output);

         bw.newLine();      

      }

      }

       br.close();

       bw.close();      

   }

  

   public static BufferedReader readFile() throws FileNotFoundException

   {

       File file = new File(\"passwords\");

       return new BufferedReader(new InputStreamReader(new FileInputStream(file)));      

   }

  

   public static BufferedWriter writeFile() throws FileNotFoundException

   {

       File file = new File(\"passwordOutput\");

       return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));

   }

}

Java program with wrapper classes (I assume): Write the following program: A program that checks a text file of passwords and verifies the passwords follow the
Java program with wrapper classes (I assume): Write the following program: A program that checks a text file of passwords and verifies the passwords follow the
Java program with wrapper classes (I assume): Write the following program: A program that checks a text file of passwords and verifies the passwords follow the
Java program with wrapper classes (I assume): Write the following program: A program that checks a text file of passwords and verifies the passwords follow the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site