Question

In: Computer Science

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 to the main method.

Follow these rules for a valid password:

  • The password must be at least 5 characters long
  • The password must have at least one uppercase and one lowercase letter
  • The password must have at least one digit

Solutions

Expert Solution

The program as per the requirement given in the problem is as follows:

Program:

import java.util.*;
class validatePassword
{
   static int same(String str1, String str2)
   {
       if(str1.equals(str2))
           return 1;
       else
           return 0;
   }
  
   static int getLength(String str)
   {
       int l=str.length();
       if(l>=5)
           return 1;
       else
           return 0;
   }

   static int getUppercase(String str)
   {
       int count=0;
       for(int i=0;i<str.length();i++)
       {
           if((int)str.charAt(i)>=65&&(int)str.charAt(i)<=90)
               count++;
       }
       if(count>=1)
           return 1;
       else
           return 0;
   }

   static int getLowercase(String str)
   {
       int count=0;
       for(int i=0;i<str.length();i++)
       {
           if((int)str.charAt(i)>=97&&(int)str.charAt(i)<=122)
               count++;
       }
       if(count>=1)
           return 1;
       else
           return 0;
   }

   static int getDigit(String str)
   {
       int count=0;
       for(int i=0;i<str.length();i++)
       {
           if((int)str.charAt(i)>=48&&(int)str.charAt(i)<=57)
               count++;
       }
       if(count>=1)
           return 1;
       else
           return 0;
   }

static int validateP(String str)
{
   int length,uppercase,lowercase,digit;
   length=getLength(str);
   uppercase=getUppercase(str);
   lowercase=getLowercase(str);
   digit=getDigit(str);
   if(length==1&&uppercase==1&&lowercase==1&&digit==1)
       return 1;
   else
       return 0;
}

   public static void main(String args[]   )
   {
      
       Scanner sc=new Scanner(System.in);
       int valid;
       do
       {
           System.out.print("Enter your password: ");
           String password=sc.nextLine();
           System.out.print("Confirm your password: ");
           String confirmPassword=sc.nextLine();
           valid=same(password,confirmPassword);
           if(valid==1)
           {
               valid=validateP(password);
               if(valid==1)
                   System.out.println("Validated.");
               else
                   System.out.println("Try again.");
           }
           else
           {
               System.out.println("Try again.\n");
               valid=0;
           }
       }while(valid==0);
   }
}
      

Screenshot of the Code:

Output 1:

Output 2:


Related Solutions

C# Create an application that asks the user to enter their new password. The password must...
C# Create an application that asks the user to enter their new password. The password must be at least 6 characters long. Develop a custom exception handling case that checks for the password length. (hint: use " .Length " built-in method). If the new password is less than 6 characters long the custom exception should output an error message.
Java Programing Write a program called reverseProg.   This program will do the following Asks the user...
Java Programing Write a program called reverseProg.   This program will do the following Asks the user to input a string, it reads the string and does the followings Prints the string in reverse order. Displays the characters that are in position 7th, 8th and 9th of this string Displays the length of the string Displays the string in all UPPER CASE Sample output example: Enter a string: Wilmington University String Entered is: Wilmington University Wilmington University spelled backward is: ytsirevinU...
Write a program that accepts user’s name, password and address and display them back using the...
Write a program that accepts user’s name, password and address and display them back using the format “Hi, I am user’s name. I live at user’s address.”. Restrictions: ▪ Use only three variables. ▪ Make sure you support spaces.
PROGRAM INSTRUCTIONS: 1. Code an application that asks the customer for a log-in and password. 2....
PROGRAM INSTRUCTIONS: 1. Code an application that asks the customer for a log-in and password. 2. The real log-in is "Buffet2011" and the real password is "Rank1Bill2008". 3. Allow the customer two (2) attempts to type either. a. Each time the customer enters an invalid log-in or password issue an error message. b. If the customer fails all two (2) log-in attempts, issue another error message and exit the program. c. If the log-in is successful, the customer can calculate...
•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...
•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...
Write a program called Assignment3 (saved in a file Assignment3 .java) that asks a user to...
Write a program called Assignment3 (saved in a file Assignment3 .java) that asks a user to enter two strings. First, the program prompts: Please enter a string. The program should read in the string, and prompts: Please enter another string. The program reads in two strings and it prints a menu to the user. The program asks for user to enter an option and performs one of the following: Here are the options on the menu: Option a: checks if...
In PYTHON: Write a program that asks for a password from a user and checks if...
In PYTHON: Write a program that asks for a password from a user and checks if it satisfies the conditions: Contains at least one lowercase letter (a-z). Contains at least one uppercase letter (A-Z). Contains at least one digit (0-9). Minimum length 6 characters. Contains no spaces. If the password is valid, then the program prints “password accepted”. Otherwise, it keeps asking for more passwords from the user until a valid password is obtained. Hint: You might like to check...
create a program that asks the user’s height What is your height? Use the input function...
create a program that asks the user’s height What is your height? Use the input function to ask this question If the answer to question 1 is greater than or equal to five, print "Yay! You can get on the rides alone" If the answer to question 1 is less than five and greater than four, print "You must be accompanied by an adult" Otherwise, print "Sorry you’re not allowed on the rides"
Write a Java application that implements the following: Create an abstract class called GameTester. The GameTester...
Write a Java application that implements the following: Create an abstract class called GameTester. The GameTester class includes a name for the game tester and a boolean value representing the status (full-time, part-time). Include an abstract method to determine the salary, with full-time game testers getting a base salary of $3000 and part-time game testers getting $20 per hour. Create two subclasses called FullTimeGameTester, PartTimeGameTester. Create a console application that demonstrates how to create objects of both subclasses. Allow the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT