473,323 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

how to limit 3 login attempts?

2
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

✓ answered by chaarmann

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.

2 14469
chaarmann
785 Expert 512MB
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
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
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
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
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
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
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
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
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
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
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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.