Question

In: Computer Science

Semester 2019 Java Programming Project 3: Loops, Strings, and Character Methods Having a secure password is...

Semester 2019
Java Programming Project 3: Loops, Strings, and Character Methods


Having a secure password is a very important practice, particularly when much of our personal information is stored online.

Please write a program that validates a new password, following these 4 rules:

The password must be at least 8 characters long.
The password must have at least one upper case letter.
The password must have at least one lower case letter.
The password must have at least one digit.
1) Your program should ask for a password, and then check first to see if the password is valid (i.e., conforms to the specifications outlined above.) If not, the program should allow the user to continue to enter passwords until s/he enters a valid password.

2) Then your program should confirm the password by requesting that the user enter the password again, and verify that the two match. If they don't match, allow the user to try it again (for a total of 3 tries only).

You will need a minimum of two methods, one to confirm the two passwords, and at least one (or more) to check to see if the password meets the 4 required specifications outlined above.

Carefully examine and follow ALL the program requirements. Make sure you use prologue comments for your program, including prologue comments for each of your methods. You will find both the Java String methods as well as the Character Class Methods immensely helpful for this Lab. Please use comments as well for any part of your code that may not be self-explanatory or may require some additional documentation.

You will find both the Java String methods as well as the Character Class Methods immensely helpful for this Lab.

SUBMISSION GUIDELINES:

1) Please write and submit an algorithm (in class) to help you with the design phase of this lab.

2) Submit a hard copy of your Java program (in class).

3) Attach your java program online in the Assignments tool. Go to Assessments-->Assignment --> Java Programming Project 3.

4) Submit a hard copy of program output or output screen shots of your program in action illustrating its functionality. You should show at least 3 program runs.


Solutions

Expert Solution

// Java program to input two passwords and check if both the passwords match
import java.util.Scanner;

public class PasswordChecker {
  
   // method to return if password is valid or not i.e it follows all the 4 rules
   private static boolean validPassword(String password)
   {
       boolean lengthValid = false, upperValid = false, lowerValid = false, digitValid = false;
       // check if length of password is atleast 8 characters long
       if(password.length() >= 8)
           lengthValid = true;
      
       // loop to check if password contains atleast one lowercase, uppercase and digit
       for(int i=0;i<password.length();i++)
       {
          
           // check if ith character is uppercase
           if(Character.isUpperCase(password.charAt(i)))
               upperValid = true;
           // check if ith character is lowercase  
           else if(Character.isLowerCase(password.charAt(i)))
               lowerValid = true;
           // check if ith character is digit
           else if(Character.isDigit(password.charAt(i)))
               digitValid = true;
       }
      
       // return if the password is valid
       return(lengthValid && upperValid && lowerValid && digitValid);
   }
  
   // method to return if the both passwords match
   private static boolean samePassword(String password, String confirmPassword)
   {
       return(password.equals(confirmPassword));
   }

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);
       String password, confirmPassword;
       boolean correctPassword = false;
       // input the password
       System.out.print("Enter password : ");
       password = scan.nextLine();
      
       // loop to validate password and re-prompt until valid
       while(!validPassword(password))
       {
           System.out.println("Invalid password");
           System.out.print("Enter password : ");
           password = scan.nextLine();
       }
      
       // loop to input the passwords again and allow the user 3 tries
       for(int i=0;i<3;i++)
       {
           System.out.print("Enter the password again : ");
           confirmPassword = scan.nextLine();
           // check if password is same
           if(samePassword(password,confirmPassword))
           {
               correctPassword = true;
               break;
           }
       }

       // check if passwords match after 3 tries and display the message accordingly
       if(!correctPassword)
           System.out.println("Both passwords doesn't match");
       else
           System.out.println("Both passwords match");
      
       scan.close();
   }

}
//end of program

Output:


Related Solutions

Having a secure password is a very important practice, when much of our information is stored...
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 8 characters long. •The password must have at least one uppercase and 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 the passwords don’t match or the rules are...
Class Instructions You will create a password verification program using C-strings and character testing. The user...
Class Instructions You will create a password verification program using C-strings and character testing. The user will enter a password as a C-string. (Character array). You must test that the password contains at least: One lowercase letter One uppercase letter One number (0-9) The password can contain no spaces You are to add one more requirement to the password. I need help in setting this program up. #include <iostream> #include <cctype> using namespace std; int main() { char input; cout...
Objective: Write this program in the C programming language Loops with input, strings, arrays, and output....
Objective: Write this program in the C programming language Loops with input, strings, arrays, and output. Assignment: It’s an organization that accepts used books and then sells them a couple of times a year at book sale events. Some way was needed to keep track of the inventory. You’ll want two parallel arrays: one to keep track of book titles, and one to keep track of the prices. Assume there will be no more than 10 books. Assume no more...
Write a program in java which is in main and uses no classes, methods, loops or...
Write a program in java which is in main and uses no classes, methods, loops or if statements Ask the user to enter their first name Ask the user to enter their last name Print their initials followed by periods (ie. Clark Kent = C. K.) Print the number of letters in their last name
Java programming problem: For simplicity, you can consider DNA sequences as strings in the alphabet of...
Java programming problem: For simplicity, you can consider DNA sequences as strings in the alphabet of {A, C, G, T}. Implement a special hash table to store all short DNA segments of certain length (e.g., 20) found in a long DNA sequence. Every DNA segment is stored as a (key, value) pair, where the key is the sequence of the segment, and the value is the position of the segment in the DNA. For example given a DNA sequence of...
A Java question. Write the class Staff. It contains methods that manipulate an ArrayList of Strings...
A Java question. Write the class Staff. It contains methods that manipulate an ArrayList of Strings representing the names of staff members. The constructor takes an ArrayList of String names as a parameter. In addition to the constructor, you need to implement the following methods The methods 1. public boolean equals(Staff other) - Determines if the other Staff contains all the same elements in the same order as this Staff 2. public boolean sameContents(Staff other) - Determines if the other...
JAVA programming Classwork- please answer all prompts as apart of one java programming project Part A...
JAVA programming Classwork- please answer all prompts as apart of one java programming project Part A Add to your project this class Position, which has x and y coordinates. Create an abstract class GameElt, which has a String name, an int health (keep it in the range 0 to 100) and a Position pos. For GameElt, include a default constructor that starts pos at (0, 0), and a parameterized constructor that takes x and y coordinates and a name. health...
Assignment Description This assignment focuses on programming basics; expressions, variables, constants, methods, selection and loops. Danny...
Assignment Description This assignment focuses on programming basics; expressions, variables, constants, methods, selection and loops. Danny runs an ice cream shop in the inner suburbs of Melbourne. Due to the growing number of customers, Danny has decided to take on extra casual employees. In order to manage payroll for his employees, Danny has decided to develop an employee payroll management system. Details of each employee to be maintained in the system will include; employee id, name, gender (M or F),...
Introduction In this lab, we will look at various aspects of methods in Java programming such...
Introduction In this lab, we will look at various aspects of methods in Java programming such as passing arguments to a method, use of local variables, and returning a value from a method. Exercise-1: RainFall Statistisc(50 pts) Write a program that asks user the total rainfall for the last six months of two consecutive years and do the following: the total rainfall per year the average monthly rainfall (for two years) the month with the most rain (per year) You...
JAVA The previous assignment for the semester project required that you submit a document that included...
JAVA The previous assignment for the semester project required that you submit a document that included class diagram document that used UML notation. By now (if not sooner), you should have a good idea of what classes you will need to include in your Java Application.You may, in fact, had identified additional classes you need to implement. For this assignment, you are to write your classes that are required for your Java application (minimum of three). Additionally, you will need...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT