Question

Write Java program: • Is at least 8 characters long • Contains at least 1 lower letter charact...

Write Java program:

• Is at least 8 characters long
• Contains at least 1 lower letter character
• Contains at least 1 upper letter character
• Contains at least 1 numeric digit
• Contains at least 1 special character from the set: !@#$%^&*
• Does not contain the word “and” or the word “the”
Prompts the user for a password, including the requirements above in your output.
Output a string that states valid or invalid. If invalid, state which rules from the list
above have not been met, and prompt the user to enter another password.
Utilize the following functionality:
• indexOf
• Looping structure
• charAt()
• isDigit()
• isUpperCase()
• isLowerCase()
• and any additional functionality needed
0 0
Add a comment Improve this question Transcribed image text
Answer #1

PasswordChecker.java

import java.util.*;
class PasswordChecker
{
public static boolean isValid(String password)
{
String symbol = "!@#$%^&*";
int upperCaseCount = 0;
int lowerCaseCount = 0;
int digitCount = 0;
boolean hasSymbol = false;
if(password.length() >= 8) {//Checks for length.
int i = 0;
while( i < password.length()) //For each character.
{
char c = password.charAt(i);
if(Character.isUpperCase(c) ) //If uppercase, increment counter.
upperCaseCount++;
if(Character.isLowerCase(c)) //If lowercase, increment counter.
lowerCaseCount++;
if(Character.isDigit(c)) //If digit, increment counter.
digitCount++;
if(symbol.indexOf(c) != -1 && hasSymbol == false) //If has symbol, mark flag.
hasSymbol = true;
i++;
}
} else {
System.out.println("Invalid password. Password length should be no less than 8.");
return false;
}
if(upperCaseCount < 1) {
System.out.println("Invalid password. Password should contain minimum 1 uppercase letter.");
return false;
}
if(lowerCaseCount < 1) {
System.out.println("Invalid password. Password should contain minimum 1 lowercase letter.");
return false;
}
if(digitCount < 1) {
System.out.println("Invalid password. Password should contain minimum 1 digits.");
return false;
}
if(!hasSymbol) {
System.out.println("Invalid password. Password should contain atleast one special characters from ! @ # $ % ^ & * ");
return false;
}
return true;
}
public static void main(String args[]){
   Scanner scan = new Scanner(System.in);
   System.out.print("Ennter the password: ");
   String pass = scan.next();
   while(!isValid(pass)){
       System.out.print("Ennter the password: ");
   pass = scan.next();
          
   }
   System.out.println("Given password is valid");
}
}

Output:

Ennter the password: pass
Invalid password. Password length should be no less than 8.
Ennter the password: password
Invalid password. Password should contain minimum 1 uppercase letter.
Ennter the password: Password
Invalid password. Password should contain minimum 1 digits.
Ennter the password: Password12
Invalid password. Password should contain atleast one special characters from ! @ # $ % ^ & *
Ennter the password: Password12!@
Given password is valid

Add a comment
Know the answer?
Add Answer to:
Write Java program: • Is at least 8 characters long • Contains at least 1 lower letter charact...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Design and implement a Java program (name it PasswordTest) that accepts a string from the user...

    Design and implement a Java program (name it PasswordTest) that accepts a string from the user and evaluates it as a password, giving it a valid or invalid verdict A good password will be at least 8 characters and includes at least one lower-case letter, at least one upper-case letter, at least one digit, and at least one character that is neither a letter nor a digit. Your program will need to check each character in the string in order...

  • Please make this Python code execute properly. User needs to create a password with at least...

    Please make this Python code execute properly. User needs to create a password with at least one digit, one uppercase, one lowercase, one symbol (see code), and the password has to be atleast 8 characters long. try1me is the example I used, but I couldn't get the program to execute properly. PLEASE INDENT PROPERLY. def policy(password): digit = 0 upper = 0 lower = 0 symbol = 0 length = 0 for i in range(0, len(password)): if password[i].isdigit(): # checks...

  • Write a program that inputs a string from the user representing a password, and checks its...

    Write a program that inputs a string from the user representing a password, and checks its validity. A valid password must contain: -At least 1 lowercase letter (between 'a' and 'z') and 1 uppercase letter (between 'A' and 'Z'). -At least 1 digit (between '0' and '9' and not between 0 and 9). At least 1 special character (hint: use an else to count all the characters that are not letters or digits). -A minimum length 6 characters. -No spaces...

  • FOR JAVA: Summary: Write a program to assess password stringency. The solution should be named Password.java....

    FOR JAVA: Summary: Write a program to assess password stringency. The solution should be named Password.java. Include these steps: Write an application that provides the criteria for a strong password, and accepts a user's password from an input dialog box. If the entered password is less than six characters, more than 10 characters, or does not contain at least one uppercase letter and one digit, prompt the user to enter again. When the user's entry meets all the password requirements,...

  • please help me out and input values please .. main cpp.. please follow intructions exactly witj...

    please help me out and input values please .. main cpp.. please follow intructions exactly witj clarity please CSE 110-Intro to Computer Programming Project #3 Requirements-String Class Functions and Test Case Documentation Using the String Class, design and develop a multi-file password validation program and Test case Document (10% of grade) that requests a password, and validates it based on the following criteria. The password must be at least 8 characters long, contain at least one number, and at least...

  • Write the Code in C program. Create a random password generator that contains a user-specified number...

    Write the Code in C program. Create a random password generator that contains a user-specified number of characters. Your program should prompt the user for the desired length of the password. Length of password: To create your password, use the random number generator in the stdlib.h C library. To generate random numbers, you will need the srand() and rand() functions. srand(seed) is used to "seed" the random number generator with the given integer, seed. Prompt the user for the seed...

  • Write a program that asks the user to enter a password, and then checks it for...

    Write a program that asks the user to enter a password, and then checks it for a few different requirements before approving it as secure and repeating the final password to the user. The program must re-prompt the user until they provide a password that satisfies all of the conditions. It must also tell the user each of the conditions they failed, and how to fix it. If there is more than one thing wrong (e.g., no lowercase, and longer...

  • C++ Loops homework Prompt the user for a desired password, input the password. Your program may...

    C++ Loops homework Prompt the user for a desired password, input the password. Your program may assume without checking that there is no input failure and that the password contains no white space. Let's say the rules for a legal password are: # chars must be in [4, 8] # digs must be >= 2 The password must contain at least one letter of each case The password must contain at least one char that's not a letter or digit...

  • Today you are to write a Java program that will prompt for and read 2 words...

    Today you are to write a Java program that will prompt for and read 2 words of equal length entered by the user, and create a new word which contains the last letter of the 1st word, the last letter of the 2nd word, followed by the second to last character of the 1st word, followed by the second to last character of the 2nd word and so on. Be sure to use the same format and wording as in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT