Question

In: Computer Science

Having a secure password is a very important practice, when much of our information is stored...

Having a secure password is a very important practice, when much of our information is stored online. Write a program that validates a new password, following these rules:

•The password must be at least 8 characters long.

•The password must have at least one uppercase and one lowercase letter

•The password must have at least one digit.

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.

In java 1.7

Solutions

Expert Solution

Console Based Password Validation Program :

package Library;

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ValidatePassword {

   public static void main(String[] args) {
      
       Scanner sc = new Scanner(System.in);
  
       boolean isNotValid = true;
       while(isNotValid) {
           System.out.println("Enter Password : ");
           String pwd = sc.nextLine();
          
           System.out.println("Confirm Password : ");
           String cPwd = sc.nextLine();
          
           if(!isValidPassword(pwd)) {
               isNotValid = true;
               System.out.println("Your password doesn't match the criteria of a valid paasword");
           }
           else if(!confirmPassword(pwd, cPwd)) {
               isNotValid = true;
               System.out.println("Your password and Confirmed password does not match.");
           }else {
               isNotValid = false;
               break;
           }
       }
      
       System.out.println("Password created successfully.");
      

   }
  
   public static boolean
isValidPassword(String password)
{
  
// Regex to check valid password.
String regex = "^(?=.*[0-9])"//represents a digit must occur at least once
+ "(?=.*[a-z])(?=.*[A-Z])"//) represents a lower and upper case alphabet must occur at least once.
+ "(?=\\S+$).{8,}$"; //represents at least 8 characters
  
// Compile the ReGex
Pattern p = Pattern.compile(regex);
  
// If the password is empty
// return false
if (password == null) {
return false;
}
  
// Pattern class contains matcher() method
// to find matching between given password
// and regular expression.
Matcher m = p.matcher(password); //Matches the given string with the Regex
  
// Return if the password
// matched the ReGex
return m.matches();
}
  
   public static boolean confirmPassword(String pwd, String cPwd) {
       if(pwd.equals(cPwd)) return true;
       else return false;
   }
  

}


Related Solutions

Ethical practice is very important, not just in research, but professional practice as well.
 Ethical practice is very important, not just in research, but professional practice as well. Because of this, ethical conduct in clinical practice holds this principle as preeminent, just as it is in the research realm: Select one: a. Safeguarding client welfare b. Competent clinical conduct C. Responsibility to the public x d. Responsibility to the profession
Description: Our solar system is very diverse when it comes to the gas composition on our...
Description: Our solar system is very diverse when it comes to the gas composition on our planets. On Mercury, which has almost no atmosphere, the pressure is less than 10-14 bar. Venus on the other hand has a much more dense atmosphere than earth, with a pressure of 92 bar. Instructions: Write a response to the following prompt and then respond to your peers. Would having different atmospheric pressures have an effect on the accuracy of gas laws? If so,...
Chemical compounds (like; H2O, NaCl,...) are very important to our life. Beside being part of our...
Chemical compounds (like; H2O, NaCl,...) are very important to our life. Beside being part of our body and necessary components for its proper functions, they are also important to the healthy growing of the plants. Give the name and chemical formulas of two chemical compounds and discuss their functions. do not repeat any compounds in this list (C6H10O5)n C9H10O2,C10H12O3,C11H14O4 – Glucose (C6H12O6 Starch (C6H10)5) CaCl2 H3PO4 Carbon Dioxide Glucose Chlorophyll (C55H72O5N4Mg) Quercetin (C15H10O7) Baking Soda NaHCO3 Nitrous oxide Magnesium Sulfate...
The elimination patterns of our patients are very important to know as we continue to assess...
The elimination patterns of our patients are very important to know as we continue to assess and do our care plans. How can impaired elimination affect the integumentary system?
During the very first step of titration of an unknown acid, is it important how much...
During the very first step of titration of an unknown acid, is it important how much distilled water we add?(after pipetting 10 ml of the unknown acid) Does it have to be just enough to soak the pH electrode or it is important and we have to be precise with it as it defines the molarity? THE QUESTION IS ABOUT ACID-BASE TITRATION. Please answer legibly. Please EXPLAIN your answer. (yes and no is not enough). THANK YOU FOR YOUR HELP.
Considering the information stored in the Sports Physical Therapy database, what security measures are important?
Considering the information stored in the Sports Physical Therapy database, what security measures are important? 
Pro's and Con's about having so much genomic data at our fingertips? Continuously evolving
Pro's and Con's about having so much genomic data at our fingertips? Continuously evolving
It is very important to understand various terms associated with the calculation of break-even. Let’s practice...
It is very important to understand various terms associated with the calculation of break-even. Let’s practice understanding this terminology by assuming that you own a dog grooming business. You will use the dog grooming service as a basis when answering the following questions; this assignment does not pertain to the health care business that you are creating for this class: 1. Research the concept of the break-even point. Why is it important for you to know how many dogs must...
our heart is a very important organ. It pumps the nutrients we need to all parts...
our heart is a very important organ. It pumps the nutrients we need to all parts of the body. Cardiovascular disease is often preventable. Please research the causes and preventions of cardiovascular disease. which gender is more likely to get cardiovascular disease? male or female? why?
he elimination patterns of our patients are very important to know as we continue to assess...
he elimination patterns of our patients are very important to know as we continue to assess and do our care plans. How can impaired elimination affect the integumentary system? Please make an initial post by midweek, and respond to at least two other student's posts with substantial details that demonstrate an understanding of the concepts, and critical thinking. Remember that your posts must exhibit appropriate writing mechanics including using proper language, cordiality, and proper grammar and punctuation. If you refer...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT