Password Validation system: A system requires a user to enter a password. The user gets 3 attempts to enter the correct password
Write a java program that asks the user to enter a password. If they enter the wrong password,they get another chance. If they fail 3 times, the program should display “Access Denied” and terminate
import java.util.*;
class ASC
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
String correct=”abc123@”;
int attempt=0;
while(attempt<3)
{
System.out.println(“Enter the password”);
String a=s.nextLine();
if(a.equals(correct))
{
System.out.println(“Okay you can proceed..”);
break;
}
else
{
attempt++;
if(attempt==3)
{
System.out.println(“Access Denied”);
}
else
{
System.out.println(“Wrong password”);
}
}}
}
}