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

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...
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...
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...
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....
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....
Intro to Java. Creating random SSN
Create a Java program which includes the following: Uses a random value as well as manipulates string and character objects in order to make an SS# (xxx-xx-xxxx).First 3 Numbers: Create a three digit random integer named FirstThree in the range of 100- 999. (10 Points)Second 2 Numbers: Create a two digit number named SecondTwo by using FirstThree as follows: (10 Points) If FirstThree is 550 or less then create a 2 digit string using the name StringFirstThree from the first 2 digits of FirstThree otherwise create a 2...
JAVA write a code for Task 1 and Task 2 and pass the test cases. Imagine...
JAVA write a code for Task 1 and Task 2 and pass the test cases. Imagine you have a rotary combination lock with many dials. Each dial has the digits 0 - 9. At any point in time, one digit from each dial is visible. Each dial can be rotated up or down. For some dial, if a 4 is currently visible then rotating the dial up would make 5 visible; rotating the dial down would make 3 visible. When...
•Write a JAVA program to check a given password strength from a user's input. •Create a...
•Write a JAVA program to check a given password strength from a user's input. •Create a method to check the number of characters. It must be more than 8. •Create a method to check the password to have at least one uppercase letter. •Create a method to check the password to have at least one lowercase letter. •Create a method to check the password to have at least one digit. •Create a method to check the password to have at...
Create a Java application called ValidatePassword to validate a user’s password. Write a program that asks...
Create a Java application called ValidatePassword to validate a user’s password. Write a program that asks for a password, then asks again to confirm it. If the passwords don’t match or the rules are not fulfilled, prompt again. Your program should include a method that checks whether a password is valid. From that method, call a different method to validate the uppercase, lowercase, and digit requirements for a valid password. Your program should contain at least four methods in addition...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT