Question

Design and implement a Java program (name it Passw

0 0
Add a comment Improve this question Transcribed image text
Answer #1

PasswordTest.java

import java.util.Scanner;


public class PasswordTest {

  
   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       System.out.println("Enter password: ");
       String password = scan.next();
       boolean status = false;
       int lowerLetterCount = 0;
       int upperLetterCount = 0;
       int digitCount = 0;
       int otherLetterCount = 0;
      
       if(password.length() >= 8){
       for(int i=0; i<password.length(); i++){
           char ch = password.charAt(i);
          
           if(ch >= 'a' && ch <= 'z'){
               lowerLetterCount++;
           }
           else if(ch >= 'A' && ch <= 'Z'){
               upperLetterCount++;
           }
           else if(ch >= '1' && ch <= '9'){
               digitCount++;
           }
           else{
               otherLetterCount++;
           }
       }
       }
       if(lowerLetterCount > 0 && upperLetterCount > 0 && digitCount > 0 && otherLetterCount > 0){
           status = true;
       }
       String s = "";
       if(status){
           s = "Valid";
       }else{
           s = "Invalid";
       }
       System.out.println("Entered Password: "+password );
       System.out.println("Verdict: "+s);

   }

}

Output:

Enter password:
CS1301/99
Entered Password: CS1301/99
Verdict: Invalid

Add a comment
Know the answer?
Add Answer to:
Design and implement a Java program (name it PasswordTest) that accepts a string from the user...
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
  • 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...

  • in C++, Design a program that asks the user to enter a password, and then analyze...

    in C++, Design a program that asks the user to enter a password, and then analyze the password, and then analyze the password for the following weaknesses: 1. Fewer than 8 characters 2. Does not contain at least one uppercase letter and one lowercase latter 3. Does not contain at least one numeric digit 4. Does not contain at least one special character( a character that is not a letter or numeric digit) 5. Is a sequence of consecutive uppercase...

  • 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...

  • Design a Java program to reset a user's password. The password must consist of exactly six...

    Design a Java program to reset a user's password. The password must consist of exactly six characters, of which one must be a digit, one must be an uppercase letter, and one must be a lowercase letter. Tell the user if the password is correct or if incorrect tell them what is wrong with it. For example, you could say: "Not valid! the password must have 6 characters! Goodbye!" Can't contain loops. Using Boolean, String, Int, char

  • 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,...

  • 4: A certain computer program is accessed by entering a user-defined password. If the password a. can contain any lo...

    4: A certain computer program is accessed by entering a user-defined password. If the password a. can contain any lowercase letter, uppercase letter, or digit from 0-9, and must contain 10 characters, how many possible passwords are there if no character can be used more than once? Express your answer as a factorial statement. Is 8 an example of permutations or combinations? b. 4: A certain computer program is accessed by entering a user-defined password. If the password a. can...

  • 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...

  • 1. Write a C++ program called Password that handles encrypting a password. 2. The program must...

    1. Write a C++ program called Password that handles encrypting a password. 2. The program must perform encryption as follows: a. main method i. Ask the user for a password. ii. Sends the password to a boolean function called isValidPassword to check validity. 1. Returns true if password is at least 8 characters long 2. Returns false if it is not at least 8 characters long iii. If isValidPassword functions returns false 1. Print the following error message “The password...

  • Write a program that separately prompts the user for a first name and last name and...

    Write a program that separately prompts the user for a first name and last name and outputs a string containing the following information, in order: a. First letter of the user's name. b. First five letters of the user's last name. c. A random two-digit integer You must construct the desired string ensuring all characters are lowercase; output the identification string accordingly. Assume the last name contains at least 5 characters. You must use the Random (java.util.Random) class to generate...

  • Create a program via Java that has atleast 8 characters long, one upper case, and one...

    Create a program via Java that has atleast 8 characters long, one upper case, and one lower case, and one digit. here is my code:     public static void main(String[] args)     {         //variables defined         String passwords;         char password =0;                 //settings up password condition to false         boolean passwordcondition= false;         boolean size=false;         boolean digit=false;         boolean upper=false;         boolean lower=false;         //inputting a scanner into the system         Scanner keyboard = new Scanner(System.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