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.

  • Write a sql program for password requirment: I just need sql query. Passwords are required for...

    Write a sql program for password requirment: I just need sql query. Passwords are required for all accounts: Passwords must have a minimum length of 10 characters; Passwords must have complexity (at least one numeric mixed with alphabetic characters. Upper case and special characters will be allowed but not forced); Passwords must be changed at least every 90 days; and, Passwords must be forced to be different than the previous 6 passwords. Intruder lockout settings are required for all accounts:...

  • 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...

  • USING JAVA Having a secure password is a very important practice when much of our information...

    USING JAVA Having a secure password is a very important practice when much of our information is stored online. Write a program that validates a new password, following these rules: The password must be at least 10 characters long. The password must have a least two uppercase and at least one lowercase letter The password must have at least one digit Write a program that asks for a password, then asks again to confirm it. If passwords don't match or...

  • Password Validation Write a program called PasswordValidationYourLastName that validates a new password, following these guidelines: Must...

    Password Validation Write a program called PasswordValidationYourLastName that validates a new password, following these guidelines: Must be at least 8 characters Must have at least 1 uppercase letter Must have at least 1 lowercase letter Must have at least 1 digit Write a program that asks for a password, and then asks again to confirm it (you can use the scanner or JOptionPane). Pass those two Strings to a method called validatePassword( ). Your validatePassword( ) should return a boolean...

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