473,503 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to limit 3 login attempts?

2 New Member
here are my codes
Expand|Select|Wrap|Line Numbers
  1. int counter = 0;
  2.         int i = 0;
  3.         // for (int i = 0; i <= 3; i++) {
  4.         while (i < 3) {
  5.             String au = ausernametxt.getText();
  6.             String ap = apasswordtxt.getText();
  7.  
  8.             String pass = "111";
  9.             String user = "zsa";
  10.  
  11.             if (user.equals(ausernametxt.getText()) && (pass.equals(apasswordtxt.getText()))) {
  12.                 JOptionPane.showMessageDialog(null, "Successfully log in!");
  13.                 new menu().setVisible(true);
  14.  
  15.             }
  16.  
  17.             if (user != (ausernametxt.getText()) && (pass.equals(apasswordtxt.getText()))) {
  18.                 JOptionPane.showMessageDialog(null, "Invalid User No", "LOG IN", JOptionPane.ERROR_MESSAGE);
  19.                 counter += 1;
  20.                 System.out.println(counter);
  21.  
  22.             }
  23.  
  24.             if (user.equals(ausernametxt.getText()) && (pass != (apasswordtxt.getText()))) {
  25.                 JOptionPane.showMessageDialog(null, "Invalid Password", "LOG IN", JOptionPane.ERROR_MESSAGE);
  26.                 counter++;
  27.                 System.out.println(counter);
  28.  
  29.             } else {
  30.  
  31.  
  32.                 JOptionPane.showMessageDialog(null, "You Inputed 3 wrong password/Username", "LOG IN", JOptionPane.ERROR_MESSAGE);
  33.  
  34.                 System.exit(0);
  35.             }
  36.  
  37.         }
May 25 '15 #1
2 14544
chaarmann
785 Recognized Expert Contributor
Delete the else in line 29. So if the counter reaches 3, your loop ends and lines 32 to 34 will be executed.
Of course you don't want to execute these two lines if you successfully logged in, so insert a "return" at line 14.
Last not least change the "if" in line 24 to an "else if", becuase you don't want to execute the following lines if you already executed 18 to 20.
May 28 '15 #2
zsazsa
2 New Member
Thank you for the answer :)
Jun 2 '15 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2365
by: tchangmian | last post by:
I want to limit user login by writing ASP program. In details, if a user had logged in wrongly for more than three times, then the user will not be abled to log in to the system anymore even...
1
1669
by: tchangmian | last post by:
Hi all, If the user had log in with correct user id but wrong password, i would like to capture the time when the user fail to login for the 1st time. Within 24 hours, if the user had tried to...
0
2465
by: kevincw01 | last post by:
There doesnt seem to be a reliable support channel for libgmail so i figured this group might have some people who could help. I have the latest version(from cvs) of libgmail.py, lgconstants.py...
5
2372
by: Matthew Louden | last post by:
I wrote ASP.NET application that access SQL Server database. When I run the application, it yields "Login failed for user '<COMPUTER_NAME>\ASPNET'" error message. I then did the following, but...
18
2699
by: icesh | last post by:
hi i'm a newbie in php.. can you help me how to make several login attempt in php? (if we put wrong password/username,, we will go back to the previous form and we can try 3 more attempts to input...
1
4452
by: dharmbhav | last post by:
Hi, I am designing a login mechanism for a website. Presently, I am blocking the user account for 1 hour if there are 3 failed login attempts with-in 1 hour. However, I want to know if there is...
17
9575
by: RRosebury | last post by:
I'm in the process of making a website, I know the basics of PHP etc.. and have a page where a user has to sign up and activiate thier account via e-mail, when they clikc the link it change a field...
3
6565
by: Jesse Jones | last post by:
I have a login form in my access database that is working perfectly. I would like to count how many times the command button is clicked so I can do things such as close the program aftr so many...
1
2993
by: jananikrishnan | last post by:
How to limit the number of login attempts to a form in a webpage? anyone please help me out...Thanks in advance
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7006
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5592
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4685
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1519
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.