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...
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...
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....
2. Write a Java program to read a string (a password)from the user and then   check...
2. Write a Java program to read a string (a password)from the user and then   check that the password conforms to the corporate password policy.   The policy is:   1) the password must be at least 8 characters   2) the password must contain at least two upper case letters   3) the password must contain at least one digit   4) the password cannot begin with a digit   Use a for loop to step through the string.   Output “Password OK” if the password...
JAVA Write a program that checks the spelling of words in a document. This program uses...
JAVA Write a program that checks the spelling of words in a document. This program uses two text files: A dictionary file containing all known correctly spelled words, and A document to be spell-checked against the dictionary. As the document to be spell checked is read, each of its words is checked against the dictionary words. The program determines whether each word is misspelled. Misspelled words are recorded. is spelled correctly. Correctly spelled words are recorded and their frequency counted....
Write a recursive a Java code that checks if a number is Palindrome. A palindrome number...
Write a recursive a Java code that checks if a number is Palindrome. A palindrome number is a number that reads the same from beginning to end and from end to beginning, in other words, a palindrome number remains the same when its digits are reversed. For example, 13431 is a palindrome number. 2332 is another one. (Note: Your algorithm should define and work with an integer number) The functionality of your code should be commented to explain what you...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT