Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Your second task is to create a method called VerifyCredentials and return a Boo

ID: 3682622 • Letter: Y

Question


Your second task is to create a method called VerifyCredentials and return a Boolean variable verified. The method verify credentials will receive a username and password and will ask a user to input her password. The user has only three chances to input a wrong password until her account is locked. If the password is correct, the method should print "Correct password" and assign the value true to the variable verified. If the password is incorrect the third time, the system should print "Incorrect password, locked account" and assign the value false to the variable verified. Write the pseudocode for the method VerifyCredentials. Write the jave code for the method VerifyCredentials. Assume the method receives the username with value "mary" and password "503". Trace how your method would work for the inputs: "hi" and "hellow".

Explanation / Answer

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
   public static void main (String[] args) throws java.lang.Exception
   {
       boolean verify = verifyCredentials("mary", "503");
       System.out.println("Verify is "+verify);
   }
  
   public static boolean verifyCredentials(String username, String pass)
   {
       boolean verified = false;
       System.out.println("User " + username +" .Enter your password::");
       Scanner sc = new Scanner(System.in);
       String input = sc.nextLine();
       if(input.equals(pass))
       {
           System.out.println("Correct password");
           verified = true;
       }else
       {  
           System.out.println("Incorrect password Enter Again::");
           input = sc.nextLine();
           if(input.equals(pass))
           {
               System.out.println("Correct password");
               verified = true;
           }
           else
           {
               System.out.println("Incorrect password Enter Again::");
               input = sc.nextLine();
               if(input.equals(pass))
               {
                   System.out.println("Correct password");
                   verified = true;
               }
               else
                   System.out.println("Incorrect password. Locked account");
           }
          
       }
      
      
       return verified;
          
   }
}