Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Many systems nowadays rely on the strength of user passwords for their security and therefore impose a variety of constraints on what are considered acceptable

Many systems nowadays rely on the strength of user passwords for their security and therefore impose a variety of constraints on what are considered acceptable passwords. For instance, OSU requires that all passwords satisfy, among other criteria, the following conditions:

passwords must be at least 8 characters long, and

they must use at least 3 of the following 4 types of characters:

upper case letters (e.g., A, B, C, ...)

lower case letter (e.g., a, b, c, ...)

digits (e.g., 1, 2, 3, ...)

special characters (e.g., !, @, $, %, ...)

For this lab, you will implement a program that checks whether a string entered by the user meets several criteria to qualify as a valid password.

Setup

Follow these steps to set up a project for this lab.

Create a new Eclipse project by copying ProjectTemplate. Name the new project PasswordChecker.

Open the src folder of this project and then open (default package). As a starting point you should use ProgramWithIOAndStaticMethod.java. Rename it CheckPassword and delete the other files from the project.

Method

Edit CheckPassword.java (including updating comments appropriately) to ask the user for a string (a password candidate), input it, and let the user know whether it satisfies certain criteria, and if not, which one(s) it fails to satisfy. You will do this in stages. In this first step, only check that the string satisfies the length requirement. In the next few steps, you will add other checks. Test your program after adding each new check to increase your confidence that the program is working. All the checks should be done in a static method declared as follows:

1

2

3

4

5

6

7

8

9

10

/**

* Checks whether the given String satisfies the OSU criteria for a valid

* password. Prints an appropriate message to the given output stream.

*

* @param passwordCandidate

* the String to check

* @param out

* the output stream

*/

private static void checkPassword(String passwordCandidate, SimpleWriter out) {...}

The String methods are summarized here. The int method length() will be useful in completing this first task.Now add a check to checkPassword that the string also contains an upper case letter. For this check you should implement and use another static method declared as follows:

1

2

3

4

5

6

7

8

/**

* Checks if the given String contains an upper case letter.

*

* @param str

* the String to check

* @return true if str contains an upper case letter, false otherwise

*/

private static boolean containsUpperCaseLetter(String str) {...}

You may find the boolean static method Character.isUpperCase(char) and the String class char method charAt(int) useful.

In a similar fashion, add checks to checkPassword that the string contains a lower case letter and that it contains a digit. Declare and use appropriate static methods following the example of containsUpperCaseLetter. The boolean static methods Character.isLowerCase(char) and Character.isDigit(char) can simplify this task. Also modify checkPassword so that it rejects a password if it does not contain characters from at least two of the three types checked so far (upper case letters, lower case letters, and digits).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

More Books

Students also viewed these Databases questions

Question

Distinguish between formal and informal reports.

Answered: 1 week ago