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.
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.
•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...
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 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...
Create an application that asks a user to answer 5 math questions. JAVA
Create an application that asks a user to answer 5 math questions. JAVA
Java - Write a program to calculate a user’s BMI and display his/her weight status. The...
Java - Write a program to calculate a user’s BMI and display his/her weight status. The status is defined as Underweight, Normal, Overweight and obese if BMI is less than 18.5, 25, 30 or otherwise respectively. You need to read weight (in kilogram) and height (in metre) from the user as inputs. The BMI is defined as the ratio of the weight and the square of the height. [10 marks]
This is Java In this problem we will write a program that asks the user to...
This is Java In this problem we will write a program that asks the user to enter a) The user's first name and b) a series of integers separated by commas. The integers may not include decimal points nor commas. The full string of numbers and commas will not include spaces either, just digits and commas. An example of valid input string is:        7,9,10,2,18,6 The string must be input by the user all at once; do not use a loop...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT