Question

Using the Java Regular Expressions API, design a class that validates the format of a user...

Using the Java Regular Expressions API, design a class that validates the format of a user input password. Specifically, you will use regular expressions to validate the syntax format and length of a password set by a user.

This included ensuring the password meets specific criteria, such as:

• Longer than a total of 8 characters

• Contains at least 1 one the following special characters: !, @, #, $, %

• Contains 1 or more numbers

• Create 1 final criteria of your own design. For example, maybe the password set cannot contain the word Password.

Be sure to document in your code’s comments and your project write-up.

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

    import java.util.Scanner;
    public class Main {
      public static void main(String[] args) {
          System.out.println("Welcome to Password Validate \n\n ");
          System.out.println("Rules for a valid Password: \n Longer than a total of 8 characters \nContains at least 1 one the following special characters: !, @, #, $, % \n Contains 1 or more numbers \n Should Contain Capital Character");
           System.out.println("Please Enter your Password :");
        Scanner sc = new Scanner(System.in);
        String s1 = sc.nextLine(); // Gets the password string from used
            boolean n = Validate.isValid(s1); // Validate class will validate the Regex Requirements
            if(n){
             System.out.println("Entered a Valid password");
            }else{
             System.out.println("Invalid password");
            }
      }
    }
    class Validate {
     
        // Below function validates the Rules
        public static boolean isValid(String password){
    if(password.matches(".*[0-9]{1,}.*") && password.matches("((?=.*[A-Z])")&&password.matches(".*[!@#$%]{1,}.*") && password.length()>=8 && password.length()<=20)
                        { //if it matches or passes all rules returns true
                                        return true;
                        }
                        else
                        {
                                        return false;
                        }
           }
        }

Add a comment
Know the answer?
Add Answer to:
Using the Java Regular Expressions API, design a class that validates the format of a user...
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
  • Design and implement a Java program (name it PasswordTest) that accepts a string from the user...

    Design and implement a Java program (name it PasswordTest) that accepts a string from the user and evaluates it as a password, giving it a valid or invalid verdict A good password will be at least 8 characters and includes at least one lower-case letter, at least one upper-case letter, at least one digit, and at least one character that is neither a letter nor a digit. Your program will need to check each character in the string in order...

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

  • Count Occurrences in Seven Integers Using Java Single Dimension Arrays In this assignment, you will design...

    Count Occurrences in Seven Integers Using Java Single Dimension Arrays In this assignment, you will design and code a Java console application that reads in seven integer values and prints out the number of occurrences of each value. The application uses the Java single dimension array construct to implement its functionality. Your program output should look like the sample output provided in the "Count Occurrences in Seven Integers Using Java Single Dimension Arrays Instructions" course file resource. Full instructions for...

  • in JAVA program.Use top-down design to design and implement a program to ask the user to...

    in JAVA program.Use top-down design to design and implement a program to ask the user to enter a list of integers, and then display to the user the mean and median of this list. You should first prompt the user to specify the length of the list of integers. For this assignment, your code should create an array of size 10, and then allow the user to specify the number of integers in their list, up to a maximum of...

  • Utilizing the class diagram above, implement the voting system using JAVA. You will need a main...

    Utilizing the class diagram above, implement the voting system using JAVA. You will need a main method to allow a voter to register and vote (you need to take in user input). You need to assume getters, setters, constructors, and toString methods; and you need to take in the user input and validate it as well. Comment the code well and submit screenshot testing within your PDF. Hint: you can research regular expressions for the validation functions. VotePersonalldentification voterLastName:String voterFirstName:String...

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

  • Homework 3: Input Validation 1   Objectives control structures console-based user input using Scanner class writing complete...

    Homework 3: Input Validation 1   Objectives control structures console-based user input using Scanner class writing complete programs using two classes: client and supplier 2   User Interface Specification This is a console-based I/O program. Display should go to System.out (print or println) and the program will get user input using the Scanner class. The flow of execution should be as follows: When the program starts, display a one-line introduction to the user Display a menu with 5 options 1. validate zip...

  • Hey all, if you could create a java program following these guidelines that would be much...

    Hey all, if you could create a java program following these guidelines that would be much appreciated. helpful comments in the program would be appreciated :) The idea of this program is as followes : A password must meet special requirements, for instance , it has to be of specific length, contains at least 2 capital letters , 2 lowercase letters, 2 symbols and 2 digits. A customer is hiring you to create a class that can be utilized for...

  • create a Java class ShiftCipher The program ShiftCipher should take two inputs from the terminal. The...

    create a Java class ShiftCipher The program ShiftCipher should take two inputs from the terminal. The first should be a string of any length which contains any type of symbol (the plaintext). The second will be a shift value which should be between 0 and 25 inclusive (though you may design your program to be resilient to shifts beyond this value). The program should print the cipher text, in which each of the alphabetic characters in the string is shifted...

  • in java please Purpose: To practice designing a class that can be used in many applications....

    in java please Purpose: To practice designing a class that can be used in many applications. To write and implement a thorough test plan. You are NOT to use any of the Java API date classes (Gregorian calendar, Date…) except for the constructor method to set the date fields to the current data. Write a class to hold data and perform operations on dates. Ie: January 2, 2019   or 3/15/2018 You must include a toString( ), an equals( ) and...

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