Question

In: Computer Science

Task Intro: Password JAVA. Write a method that checks a password. The rules for the password...

Task Intro: Password JAVA.

Write a method that checks a password. The rules for the password are:

- The password must be at least 10 characters.
- The password can only be numbers and letters.
- Password must have at least 3 numbers.
Write a test class that tests the checkPassword method.

Hint: You can (really should) use method from built-in String class:

public boolean matches(String regex)
to check that the current string matches a regular expression. For example, if the variable "password" is the string to be checked, so will the expression.
password.matches("(?:\\D*\\d){3,}.*") 

return true if the string contains at least 3 numbers. Regular expression "^ [a-zA-Z0-9] * $" can be used to check that the password contains only numbers and letters.

Let your solution consist of 4 methods:

checkPassword(string password) [only test this method]
checkPasswordLength(string password) [checkPassword help method]
checkPasswordForAlphanumerics(string password) [checkPassword help method]
checkPasswordForDigitCount(string password) [checkPassword help method]

Solutions

Expert Solution

Write a method that checks a password and The rules for the password are:

import java.util.Scanner;

class ValidatePassword {

publics static void main (String [] args) {

String inputPassword;

Scanner input = new Scanner (System.in);

System.out.print("Password: ");

inputPassword= input.next();

System.out.println(PassCheck(inputPassword));

System.out.println("");

main(args);

}

public static String PassCheck (String Password) {

String result = "Valid Password";

int length = 0;

int numCount = 0;

int capCount = 0;

for (int x =0; x < Password.length(); x++)

{

if ((Password.charAt(x) >= 47 && Password.charAt(x) <= 58) || (Password.charAt(x) >= 64 && Password.charAt(x) <= 91) ||

(Password.charAt(x) >= 97 && Password.charAt(x) <= 122))

{

}

else

{

result = "Password Contains Invalid Character!";

}

if ((Password.charAt(x) > 47 && Password.charAt(x) < 58))

{

numCount ++;

}

if ((Password.charAt(x) > 64 && Password.charAt(x) < 91))

{

capCount ++;

}

length = (x + 1);

}

if (numCount < 3)

{

result = "Not Enough Numbers in Password!";

}

if (capCount < 2) {

result = "Not Enough Capital Letters in Password!";

}

if (length < 8){

result = "Password is Too Short!";

}

return (result);

}

}

@thank you


Related Solutions

Task Intro: Password JAVA and JUnit5(UNIT TESTING) Write a method that checks a password. The rules...
Task Intro: Password JAVA and JUnit5(UNIT TESTING) Write a method that checks a password. The rules for the password are: - The password must be at least 10 characters. - The password can only be numbers and letters. - Password must have at least 3 numbers. Write a test class(Junit5/Unit testing) that tests the checkPassword method. Hint: You can (really should) use method from built-in String class: public boolean matches(String regex) to check that the current string matches a regular...
Task Intro: Password JAVA and JUnit5(UNIT TESTING) Write a method that checks a password. The rules...
Task Intro: Password JAVA and JUnit5(UNIT TESTING) Write a method that checks a password. The rules for the password are: - The password must be at least 10 characters. - The password can only be numbers and letters. - Password must have at least 3 numbers. Write a test class(Junit5/Unit testing) that tests the checkPassword method. Hint: You can (really should) use method from built-in String class: public boolean matches(String regex) to check that the current string matches a regular...
Write a Java method to check whether a string is a valid password. Password rules: A...
Write a Java method to check whether a string is a valid password. Password rules: A password must have at least ten characters. A password consists of only letters and digits. A password must contain at least two digits. There are at least SIX functions/methods as the following: 1. menu() – to print the password’s rules. 2. getString() – to get the password from the user. 3. isPassword() – to check either the password is valid based on the given...
Write a C++ program that checks if the password is correct. The password is a 4-digit...
Write a C++ program that checks if the password is correct. The password is a 4-digit number combination. The program repeats to ask the password until the password is correct or you enter -1 to exit. Input: The password is set to ‘1123’. A user input the password to proceed, or -1 to exit. Sample Output: The program should display the following output. (The red text is a user input.) Test case 1: when you enter the correct password. Enter...
In PYTHON: Write a program that asks for a password from a user and checks if...
In PYTHON: Write a program that asks for a password from a user and checks if it satisfies the conditions: Contains at least one lowercase letter (a-z). Contains at least one uppercase letter (A-Z). Contains at least one digit (0-9). Minimum length 6 characters. Contains no spaces. If the password is valid, then the program prints “password accepted”. Otherwise, it keeps asking for more passwords from the user until a valid password is obtained. Hint: You might like to check...
Write a pro-active password checker that checks to make sure that a user entered password meets...
Write a pro-active password checker that checks to make sure that a user entered password meets certain requirements. You must implement a simple program that prompts the user for two String values, a password and the same password again for confirmation. For the purposes of this lab, a legal password must have all of the following properties: ▪ Length of at least 8 characters ▪ Starts with a lower case letter ▪ Ends with a numerical digit ▪ Has one...
Please write a Java method contains that checks whether the second given character array is contained...
Please write a Java method contains that checks whether the second given character array is contained in the first given character array. We require that both of the arrays are partially filled.
Time Calculator – Intro To Programming - JAVA Write a program that asks the user to...
Time Calculator – Intro To Programming - JAVA Write a program that asks the user to enter a number of seconds. • There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds. • There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or equal to...
Hello this is an intro to CS course. The question is: Using Java, write a program...
Hello this is an intro to CS course. The question is: Using Java, write a program that asks the user to enter three numbers. Then passes these numbers to the following methods and prints out the numbers returned by these methods. largest() – returns the largest of the three numbers smallest() – returns the smallest of the three numbers median() – returns the median of the three numbers Example output is given below: Enter three numbers 10 4 16 The...
Python Coding 1. validate_username_password(username, password, users): This function checks if a given username and password matches...
Python Coding 1. validate_username_password(username, password, users): This function checks if a given username and password matches in the stored users dictionary. This function returns True if a match found otherwise returns False. 2. validate_existing_user(users): This function asks for username and password and checks if user provided name and password matches. It prints an informational message and returns username if it does find a match. Call validate_username_password() function to perform this validation. A user has total of three chances to validate....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT