Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write a Java application program that can check a password to see whether it is really secure. This program is like a password game

Please write a Java application program that can check a password to see whether it is really secure. This program is like a password game. If the password is not secure, your program must report all the security violations. Please see the following test case #1 to design your application program. You must stop your program when the password from the user is quit. You need to use scan.nextLine( ) to get the complete password.

You must write 7 methods to check the following 7 rules for a secure password.

Rule 1: Length invalid The length of the password must be 8 to 12 only.

Rule 2: No Space The password must not contain any space or blank character.

Rule 3: At least 2 digits The password must contain at least 2 digits.

Rule 4: At least 1 upper-case letter The password must contain at least one upper-case letter.

Rule 5: At least 1 lower-case letter The password must contain at least one lower-case letter.

Rule 6: At least 1 special character The password must contain at least one special character, which can be one of the following 7 choices: $, #, @, &, *, ?, or !.

Rule 7: No special numbers The password must not contain any of the following 4 numbers: 2019, 2018, 2017, or 2016.

The following is a sample standard test, which must be your test case #1. You must also do test case #2 and test case #3 with different set of input data. Each test case must test at least 5 passwords with 2 secure and 3 non-secure. All those 7 violations must appear in those 3 non-secure passwords.

Welcome to play the Password game!

Please enter a password > 0 0 7

The password 0 0 7 violates the following rules:

Rule 1: Length invalid The length of the password must be 8 to 12 only.

Rule 2: No Space The password must not contain any space or blank character.

Rule 4: At least 1 upper-case letter The password must contain at least one upper-case letter.

Rule 5: At least 1 lower-case letter The password must contain at least one lower-case letter.

Rule 6: At least 1 special character The password must contain at least one special character, which can be one of the following 7 choices: $, #, @, &, *, ?, or !.

Please enter a password > $007SLin!

Congratulations! Your password $007SLin! is very secure!

Please enter a password > #1SimonLin

The password #1SimonLin violates the following rule:

Rule 3: At least 2 digits The password must contain at least 2 digits.

Please enter a password > SLin2019@

The password SLin2019@ violates the following rule:

Rule 7: No special numbers The password must not contain any of the following 4 numbers: 2019, 2018, 2017, or 2016.

Please enter a password > $2020LinWins

Congratulations! Your password $2020LinWins is very secure!

Please enter a password > quit

Thank you for playing the Password game! Hope to see you soon!

==========================================================================.

The following is a sample code with some pseudo-code inside for this Password Game program:

package Package_CS236 ;

import java.util.*;

public class CS236_Lab1

{ static String pw; // global variable to hold password for security checking

static boolean r1,r2,r3,r4,r5,r6,r7; //7 rules satisfaction indicators: true | false

public static void main(String[] args)

{ // begin of main( ) ----------------------------------------

Scanner scan = new Scanner(System.in);

System.out.print("Please enter a password >");

pw = scan.nextLine(); // scan to get the password in pw

System.out.println("You just entered password \"" + pw + "\"");

s1(); s2(); s3(); s4();

s5(); s6(); s7(); // call 7 methods to check all 7 rules for satisfaction

if (r1 && r2 && r3 && r4 && r5 && r6 && r7) // all 7 rules are satisfied

{ /* print secure password message */ }

else // insecure password because at least one rule got violated

{ // print all the violated rules

if (!r1) /* print rule 1 */ ;

if (!r2) /* print rule 2 */ ;

if (!r3) /* print rule 3 */ ;

if (!r4) /* print rule 4 */ ;

if (!r5) /* print rule 5 */ ;

if (!r6) /* print rule 6 */ ;

if (!r7) /* print rule 7 */ ;

} // print all the violated rules

} // end of main( ) -------------------------------------------

// The following are 7 static methods to check those 7 rules:

static void s1(){ r1=false; /* if (check r1 ok) r1=true; */ }

static void s2(){ r2=false; /* if (check r2 ok) r2=true; */ }

static void s3(){ r3=false; /* if (check r3 ok) r3=true; */ }

static void s4(){ r4=false; /* if (check r4 ok) r4=true; */ }

static void s5(){ r5=false; /* if (check r5 ok) r5=true; */ }

static void s6(){ r6=false; /* if (check r6 ok) r6=true; */ }

static void s7(){ r7=false; /* if (check r7 ok) r7=true; */ }

} // end of class Password

// You may use the following ideas for upper/lower case characters checking

String upperChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; // A thru Z upper case

String lowerChar = "abcdefghijklmnopqrstuvwxyz" ; // a thru z lower case

String specialChars = "$#@&*?!" ; // 7 special characters

Some other useful functions to be used are as follows:

pw.contains("2019") will return true if pw contains 2019.

pw.contains(" ") will return true if pw contains a blank character.

pw.length( ) will return the length of the string pw.

You may need to use some String methods such as charAt, substring, length, contains, or indexOf.

A special technique to check for the Rule 3 (At least 2 digits in password) is as follows:

static void s3( ) // static method for this program

{ // begin of s3( ) method // for Rule 3 checking

char c ; int countDigits ; String digits = "0123456789" ;

countDigits = 0 ; // set 0 as the current count of digits in the password

r3 = false; // set r3 to false in the beginning

for ( int i = 0 ; i < pw.length( ) ; i++ )

{ c = pw.charAt( i ); // get the i-th char as c

if ( digits.indexOf( c ) != -1 ) countDigits++; // c is a digit, so increment countDigits

}

if (countDigits >= 2) r3 = true; // r3 is true now since at least 2 digits in the password

} // end of s3( ) method // for Rule 3 checking

You must write a while loop to keep asking for the next password until the password entered by the user is quit.

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

Database Design Using Entity Relationship Diagrams

Authors: Sikha Saha Bagui, Richard Walsh Earp

3rd Edition

103201718X, 978-1032017181

Students also viewed these Databases questions

Question

What is operating leverage? Discuss.

Answered: 1 week ago

Question

What was the positive value of Max Weber's model of "bureaucracy?"

Answered: 1 week ago

Question

5. Understand how cultural values influence conflict behavior.

Answered: 1 week ago

Question

e. What do you know about your ethnic background?

Answered: 1 week ago