Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Main.java code public class Main { public static void main(String[] args) { User user1 = new User(Michelle, 12345); System.out.println(1. + user1.isValidPassword()); // false --

image text in transcribed

Main.java code

public class Main {

public static void main(String[] args) {

User user1 = new User("Michelle", "12345");

System.out.println("1. " + user1.isValidPassword()); // false -- less than 8 characters

User user2 = new User("Michelle", "12345Michelle");

System.out.println("2. " + user2.isValidPassword()); // false -- contains username

User user3 = new User("Michelle", "12345678");

System.out.println("3. " + user3.isValidPassword()); // true

System.out.println("4. " + user2.authenticate("ABCDE")); // false -- incorrect password

System.out.println("5. " + user2.authenticate("12345Michelle")); // true

System.out.println("6. " + user3.authenticate("12345678")); // true

}

}

user.java code

public class User {

private String username;

private String password;

public User(String username, String password) {

this.username = username;

this.password = password;

}

public boolean isValidPassword() {

return password.length() >= 8 && !password.contains(username);

}

public boolean authenticate(String inputPassword) {

return inputPassword.equals(password);

}

}

For this lab you will need to download the associated .zip file from Pilot. The User class contains two fields: a username and a password. It also has two methods: isValidPassword and authenticate. A password is considered valid if it is at least eight characters long and it does not contain the username as part of the password. The authenticate method takes a String as an argument and returns true if that string matches the user's password; otherwise it returns false. The file Main.java contains code that thoroughly tests the User class. Your task for this lab is to write and test a subclass of User called SecureUser. This subclass should override the authenticate method to meet more stringent requirements. In particular, a SecureUser class should "lock" a user out after three consecutive failed authentications. In other words, the authentication method should return true only if the string passed into the method matches the password AND there have not been three consecutive failed authentications. If the user has two failed authentications and then a successful authentication, you should reset the number of consecutive failed authentications to zero. You should also add code to Main.java so that it thoroughly tests the SecureUser class. It is up to you how many tests you want to create, but keep in mind that you will not receive credit for this lab if your code to produce an incorrect response in any of our tests. You should not make any changes to User.java, and you should only add to Main.java. Do not change any code that is already present. Hint: You will probably find it useful to add a new field to the SecureUser class to keep track of the number of consecutive failed authentications

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

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

More Books

Students also viewed these Databases questions

Question

Describe the importance of global talent management.

Answered: 1 week ago

Question

Summarize the environment of recruitment.

Answered: 1 week ago