Write an application that accepts a users password from the

Write an application that accepts a user\'s password from the keyboard. When the entered password is less than six characters, more than 10 characters, or does not contain at least one letter and one digit, prompt the user again. When the user\'s entry meets all the password requirements, prompt the user to reenter the password, and do not let the user continue until the second password matches the first one.

Solution

import java.util.Scanner;

public class PAsswordCheck {

   /* This method is used to valid password given by user
   * whether method contains character, letter and numeric value
   * if contains return true or false
   *
   * @param password
   * @return boolean
   */
   public static boolean isValid(String password) {
       int length = password.length();
       boolean letter = false;
       boolean number = false;
//       check condition if character length 6-10
       if ((length >= 6) && (length <= 10)) {
           {
               for (int i = 0; i < length; i++) {
//                   check condition if password contains digit or not
                   if (Character.isDigit(password.charAt(i))) {
                       number = true;
                   }
//                   check condition if password contains letter or not
                   if (Character.isLetter(password.charAt(i))) {
                       letter = true;
                   }
               }

           }
       }
       else{
           System.out.println(\"condition failed!\");
       }
       return (number && letter);
      
      

   }

  

   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       System.out.println(\"Please enter a given password : \");
       String password = scan.nextLine();
       System.out.println(isValid(password));
       if (isValid(password)) {
           System.out.println(\"Please re-enter the password to confirm : \");
           String reEnter = scan.nextLine();
//           match both password
           if (reEnter.equalsIgnoreCase(password)) {
               System.out.println(\"passowrd saved\");
           }
           else{
               System.out.println(\"Password not matched!\");
           }
       } else {
           System.out.println(\"Invalid Passowrd. Password \" + \"must contain atleast 1 letter\" + \" 1 digit, 1\"
                   + \" and \" + \"characters between 6-10 long\");
       }
       scan.close();
   }
  

}

 Write an application that accepts a user\'s password from the keyboard. When the entered password is less than six characters, more than 10 characters, or does
 Write an application that accepts a user\'s password from the keyboard. When the entered password is less than six characters, more than 10 characters, or does

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site