Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<pre lang="java">
import java.io.*;
import java.util.*;


public class C1Task4 {

	public static void main(String[] args)throws FileNotFoundException {
		Scanner console = new Scanner(System.in);
		
		
		String NameInput;
		String PassInput;
		String NumberInput;
		int count = 0;

		System.out.println("Please enter Account Number");
		NumberInput = console.next();
		
		System.out.println("Please enter Password");
		PassInput = console.next();
		
		
	for(count=0; count<3; count++){
		
		if (PassInput.equals("Password")&& (NumberInput.equals("123321")))
		{
				System.out.println("You have logged in!");
		}
		
	
		else 

		{
			
		System.out.println("You have two more attempts to log in");
	
		}	
		}

	}
	
	}
Posted
Comments
syed shanu 7-Dec-14 21:38pm    
Can you tell me after 3 attempts what you will do.will you lock the user so that he can not login again.if its so in your table you can add one more field as count initially the count set as 0.If user logsin for first time .
Create one Storeprocedure and check for valid user if hes valid user then no need to update the countfield if the username or password failes then update the the countfiled to 1.repead this action.
In select query check for user name and password and countfield lessthen 3.
when user try login for more then 3 time display your message and do your action as you needed.
ZurdoDev 7-Dec-14 22:01pm    
Where are you stuck? You have to build this yourself.

1 solution

Try something like this:
Java
for(count = 2; count > 0; --count) {
    if (PassInput.equals("Password")&& (NumberInput.equals("123321")))
    {
        System.out.println("You have logged in!");
        count = 1; // show success
        break; // success, no more tries needed
    }
    else 
    {
        // check failed so if two fails already then break out of loop
        if (count == 0)
            break;
        // still more tries allowed
        System.out.println("You have " + count + " more attempts to log in");
    }
}
if (count == 0)
{
    // take action for login failure
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900