Question

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

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

thanks for the question, Here is the code without loops. Have used string, int, boolean, char in the code and also commented the code for you to follow it easily

thank you ! If you are satisfied please rate

=========================================================================

import java.util.Scanner;

public class PasswordReset {


    public static void main(String[] args) {


        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter password: ");
        String password = scanner.nextLine();

        boolean containsDigits = false;
        boolean containsLowerCase = false;
        boolean containsUpperCase = false;

        int passwordLength = password.length();

        // check if the password contains 6 characters
        if (passwordLength != 6) {
            System.out.println("Not valid. Password must have 6 characters! Goodbye!");
        } else {
            // store 6 letters in 6 variables
            char first = password.charAt(0);
            char second = password.charAt(1);
            char third = password.charAt(2);
            char fourth = password.charAt(3);
            char fifth = password.charAt(4);
            char sixth = password.charAt(5);
           
            // check if one of the character is digit
            if (('0' <= first && first <= '9') ||
                    ('0' <= second && second <= '9') ||
                    ('0' <= third && third <= '9') ||
                    ('0' <= fourth && fourth <= '9') ||
                    ('0' <= fifth && fifth <= '9') ||
                    ('0' <= sixth && sixth <= '9')) {
                containsDigits = true;
            }
            // check if one of the character is lower case
            if (('a' <= first && first <= 'z') ||
                    ('a' <= second && second <= 'z') ||
                    ('a' <= third && third <= 'z') ||
                    ('a' <= fourth && fourth <= 'z') ||
                    ('a' <= fifth && fifth <= 'z') ||
                    ('a' <= sixth && sixth <= 'z')) {
                containsLowerCase = true;
            }
            // check if one of the character is upper case
            if (('A' <= first && first <= 'Z') ||
                    ('A' <= second && second <= 'Z') ||
                    ('A' <= third && third <= 'Z') ||
                    ('A' <= fourth && fourth <= 'Z') ||
                    ('A' <= fifth && fifth <= 'Z') ||
                    ('A' <= sixth && sixth <= 'Z')) {
                containsUpperCase = true;
            }

            // if condition to valid password
            if(containsDigits){
                if(containsLowerCase){
                    if(containsUpperCase){
                        System.out.println("Valid. Password Accepted!");
                    }else{
                        System.out.println("Not valid! Password must contain one upper case letter.Goodbye!");
                    }
                }else{
                    System.out.println("Not valid! Password must contain one lower case letter.Goodbye!");
                }
            }else{
                System.out.println("Not valid! Password must contain one digit letter.Goodbye!");
            }

        }
    }
}

=========================================================================

thanks a lot!

Add a comment
Know the answer?
Add Answer to:
Design a Java program to reset a user's password. The password must consist of exactly six...
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
  • 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...

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

  • Python Create a function that checks user input in an attempt to create a password. The...

    Python Create a function that checks user input in an attempt to create a password. The valid_password function accepts a password as an argument and returns either true or false to indicate whether the password is valid. A valid password must be at least 7 characters in length, have at least one uppercase letter, one lowercase letter, and one digit. Respond with output to the user as to whether the password is valid or not, and allow the user to...

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

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

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

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

  • I just started working on some code for a password creator. I was doing some testing and I keep g...

    I just started working on some code for a password creator. I was doing some testing and I keep getting this error: Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 6 at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:47) at java.base/java.lang.String.charAt(String.java:693) at PasswordCreater.check(PasswordCreater.java:56) at Password.main(Password.java:23 In my code I am having the user create a password that is at least 6 characters long, but no more than 16. Also, include at least one lowercase letter, one uppercase letter, one number digit and one special...

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