Question

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);
       
            System.out.println("Please enter a password: \n (Caution must have one uppercase, one lowercase, and a digit for password to be valid!)");
            passwords=keyboard.nextLine();
      
            while(!passwordcondition)
            {

                        for (int p=0; p<passwords.length(); p++)
                        {  
                                if(Character.isDigit(p))
                                {
                                  digit = true;  
                                }
                                else if(Character.isUpperCase(p))
                                {
                                  upper = true;
                                }
                                else if(Character.isLowerCase(p))
                                {
                                  lower = true;
                                }
                                else if(passwords.length() > 8)
                                {
                                  size = true;
                                }
                        }
                       
                       
                           if(digit == true && upper == true && lower == true && size == true)
                           {
                             System.out.printf("You have entered a valid password");
                             System.exit(0);
                           }
                           else
                           {
                             System.out.println("You have entered an invalid password");
                             return;
                           }

                       
            }

    }

my problem is I cannot get it back into the loop if I have an invalid answer.

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

// I have edited the program as required

import java.util.Scanner;
public class pass
{

public static void main(String[] args)
{
//variables defined
String passwords;
char password =0;

//settings up password condition to false
boolean passwordcondition;
boolean size=false;
boolean digit=false;
boolean upper=false;
boolean lower=false;
//inputting a scanner into the system
Scanner keyboard = new Scanner(System.in);

do
{
System.out.println("Please enter a password: \n (Caution must have one uppercase, one lowercase, and a digit for password to be valid!)");
passwords=keyboard.nextLine();
char ch;

for (int p=0; p<passwords.length(); p++)
{
ch=passwords.charAt(p);
if(Character.isDigit(ch))
{
digit = true;  
}
else if(Character.isUpperCase(ch))
{
upper = true;
}
else if(Character.isLowerCase(ch))
{
lower = true;
}
else if(passwords.length() >= 8)
{
size = true;
}
}


if(digit == true && upper == true && lower == true && size == true)
{
System.out.printf("You have entered a valid password");
passwordcondition=true;
System.exit(0);

}
else
{
System.out.println("You have entered an invalid password");
passwordcondition=false;
}

}while(passwordcondition==false);
}
}

Add a comment
Know the answer?
Add Answer to:
Create a program via Java that has atleast 8 characters long, one upper case, and one...
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
  • 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...

  • I am creating a program that will allow users to sign in with a username and...

    I am creating a program that will allow users to sign in with a username and password. Their information is saved in a text file. The information in the text file is saved as such: Username Password I have created a method that will take the text file and convert into an array list. Once the username and password is found, it will be removed from the arraylist and will give the user an opportunity to sign in with a...

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

  • Im try to create a java program that checks to see if a given boolean expression...

    Im try to create a java program that checks to see if a given boolean expression is a tautology or not my code so far is as follows: public static class TreeNode    {        char data;        TreeNode left;        TreeNode right;               TreeNode(char item)        {            data = item;            left = null;            right = null;        }    } public static...

  • Write a java program. I was given the following case. Your boss has determined that employee...

    Write a java program. I was given the following case. Your boss has determined that employee passwords need to be updated and made stronger. The new password policy has the following requirements At least 8 characters in length. Must contain at least one upper case character . Must contain at least one lower case character Must contain one number character Must contain one of the following characters: @,#,%,^,&,* After a couple of weeks, your boss wants to know if all...

  • You will be writing a simple Java program that implements an ancient form of encryption known...

    You will be writing a simple Java program that implements an ancient form of encryption known as a substitution cipher or a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a "shifted" alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: A B C...

  • Java programming How do i change this program to scan data from file and find the...

    Java programming How do i change this program to scan data from file and find the sum of the valid entry and count vaild and invalid entries The provided data file contains entries in the form ABCDE BB That is - a value ABCDE, followed by the base BB. Process this file, convert each to decimal (base 10) and determine the sum of the decimal (base 10) values. Reject any entry that is invalid. Report the sum of the values...

  • Written in Java I have an error in the accountFormCheck block can i get help to...

    Written in Java I have an error in the accountFormCheck block can i get help to fix it please. Java code is below. I keep getting an exception error when debugging it as well Collector.java package userCreation; import java.io.IOException; import java.net.URL; import java.util.ResourceBundle; import java.util.regex.Matcher; import java.util.regex.Pattern; import javafx.event.ActionEvent; import javafx.fxml.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.text.Text; import javafx.stage.*; public class Controller implements Initializable{ @FXML private PasswordField Password_text; @FXML private PasswordField Confirm_text; @FXML private TextField FirstName_text; @FXML private TextField LastName_text;...

  • Java code is calculating the bill wrong and not displaying currency at the end: I've highlighted...

    Java code is calculating the bill wrong and not displaying currency at the end: I've highlighted the error in the cosole Southwest Power and Light Billing Statement Please enter your name > J, P Customer name:J, P Meter reading date > 2/15/16 Meter reading date:2/15/16 Electricity used: > 225 The basic rate is:22.5 The totalBill is 225.0 Calculate another bill? (Y/N)?: The correct answer should be baseline charge: $22.50 and total bill: $22.50 The Charges are based on these: 0kw...

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