Question

Write a java program. I was given the following case. Your boss has determined that employee...

Write a java program. I was given the following case.

Your boss has determined that employee passwords need to be updated and made stronger. The new password policy has the following requirements At least 8 characters in length. Must contain at least one upper case character . Must contain at least one lower case character Must contain one number character Must contain one of the following characters: @,#,%,^,&,* After a couple of weeks, your boss wants to know if all employee passwords now meet the new requirements. He has given you a text file (pwd.txt) and asked you to write a program that will scan the file and create two new files (invalidpwd.txt and validpwd.txt). All invalid passwords from pwd.txt will be written to invalidpwd.txt and all valid passwords from pwd.txt will be written to validpwd.txt.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

EmployeePassword.java

// Java Program to illustrate reading from FileReader
// using BufferedReader
import java.io.*;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class EmployeePassword
{
   private Pattern pattern;
   private Matcher matcher;
   //Regular expression for matching with employee password
   private static final String PASSWORD_PATTERN = "((?=.*[a-z])(?=.*\\d)(?=.*[A-Z])(?=.*[@#%^&*]).{8,40})";
   public EmployeePassword() {
pattern = Pattern.compile(PASSWORD_PATTERN);
}
public boolean passwordValidator(String password){
       matcher = pattern.matcher(password);
return matcher.matches();
   }
   public static void main(String[] args)throws Exception
   {
       // We need to provide file path as the parameter:
       // double backquote is to avoid compiler interpret words
       // like \test as \t (ie. as a escape sequence)
       EmployeePassword obj = new EmployeePassword();
       File file = new File("C:\\Users\\ExamCell2k19\\Pictures\\java\\pwd.txt");
       File invalid = new File("C:\\Users\\ExamCell2k19\\Pictures\\java\\invalidpwd.txt");
       File valid = new File("C:\\Users\\ExamCell2k19\\Pictures\\java\\validpwd.txt");
       //FileWriter is used to write into a file
       FileWriter fr1 = new FileWriter(valid);
       FileWriter fr2 = new FileWriter(invalid);
       //BufferedReader for reading the data from the file
       BufferedReader br = new BufferedReader(new FileReader(file));
       String st;
       while ((st = br.readLine()) != null) {
           boolean res = obj.passwordValidator(st);
           if(res){
               fr1.write(st);
               fr1.write("\n");
           }
           else{
               fr2.write(st);
               fr2.write("\n");
           }
       }
       fr1.close();
       fr2.close();
   }
  
}

Add a comment
Know the answer?
Add Answer to:
Write a java program. I was given the following case. Your boss has determined that employee...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that asks the user to enter a password, and then checks it for...

    Write a program that asks the user to enter a password, and then checks it for a few different requirements before approving it as secure and repeating the final password to the user. The program must re-prompt the user until they provide a password that satisfies all of the conditions. It must also tell the user each of the conditions they failed, and how to fix it. If there is more than one thing wrong (e.g., no lowercase, and longer...

  • Write Java program: • Is at least 8 characters long • Contains at least 1 lower letter charact...

    Write Java program: • Is at least 8 characters long • Contains at least 1 lower letter character • Contains at least 1 upper letter character • Contains at least 1 numeric digit • Contains at least 1 special character from the set: !@#$%^&* • Does not contain the word “and” or the word “the” Prompts the user for a password, including the requirements above in your output. Output a string that states valid or invalid. If invalid, state which...

  • i need know how Write a program that tests whether a string is a valid password....

    i need know how Write a program that tests whether a string is a valid password. The password rules are: It must have at least eight characters. It must contain letters AND numbers It must contain at least two digits It must contain an underscore (_) Write a program that prompts the user to enter a password and displays the password entered and whether it is valid or invalid.

  • Can I please get some assistance on this? 1. Write a program to test the correctness...

    Can I please get some assistance on this? 1. Write a program to test the correctness of a password according to some rules. If the password is not valid, print messages showing what's wrong with the password. Partial program output should look like this: Please enter a password. It must be at least 8 characters long and contain at least 2 alpha characters, at least one upper case and one lower case, at least 1 numbers, and at least 1...

  • Create a program via Java that has atleast 8 characters long, one upper case, and one...

    Create a program via Java that has atleast 8 characters long, one upper case, and one lower case, and one digit. here is my code:     public static void main(String[] args)     {         //variables defined         String passwords;         char password =0;                 //settings up password condition to false         boolean passwordcondition= false;         boolean size=false;         boolean digit=false;         boolean upper=false;         boolean lower=false;         //inputting a scanner into the system         Scanner keyboard = new Scanner(System.in);...

  • 2. You are making a new account on your favorite social media website. This great new...

    2. You are making a new account on your favorite social media website. This great new website offers the most fun way to steal all of your personal information! Long story short, you need a new password. ords can include upper-case letters, lower-case letters, numbers and the symbols you can r. Characters may be repeated. Please do not simplify your answers. get by holding Shift + a numbe (a) Suppose you want to make a 7, 8 or 9-character long...

  • How do I format this into C++? This the prompt: Design a class named Password that...

    How do I format this into C++? This the prompt: Design a class named Password that stores a password in a c-string and has member functions to test if the password complies with certain requirements as follows: The password should be between 6 and 20 characters long. The password should contain at least one uppercase and at least one lowercase letter. The password should have at least one digit. The password should have at least one punctuation character. Define a...

  • FOR JAVA: Summary: Write a program to assess password stringency. The solution should be named Password.java....

    FOR JAVA: Summary: Write a program to assess password stringency. The solution should be named Password.java. Include these steps: Write an application that provides the criteria for a strong password, and accepts a user's password from an input dialog box. If the entered password is less than six characters, more than 10 characters, or does not contain at least one uppercase letter and one digit, prompt the user to enter again. When the user's entry meets all the password requirements,...

  • please help me out and input values please .. main cpp.. please follow intructions exactly witj...

    please help me out and input values please .. main cpp.. please follow intructions exactly witj clarity please CSE 110-Intro to Computer Programming Project #3 Requirements-String Class Functions and Test Case Documentation Using the String Class, design and develop a multi-file password validation program and Test case Document (10% of grade) that requests a password, and validates it based on the following criteria. The password must be at least 8 characters long, contain at least one number, and at least...

  • First, launch NetBeans and close any previous projects that may be open (at the top menu...

    First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects). Then create a new Java application called "PasswordChecker" (without the quotation marks) that gets a String of a single word from the user at the command line and checks whether the String, called inputPassword, conforms to the following password policy. The password must: Be 3 characters in length Include at least one uppercase character Include at least...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT