473,657 Members | 2,566 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 14611
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
2376
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 thought he key in correctly the username and password in the 4th time. That's means he cant login forever until the administrator edit his status in the database Can i refer to any ASP sample coding for this application?
1
1684
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 log in with same user id but wrong password, the user will be locked, so that the user will unable to access the system until he contact the administrator. Can someone show me the ASP coding on how to write this? Thanks
0
2474
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 and mkconstants.py with python version 2.3.3. gmailfs fails with a login error. I also tried a test login script and it fails on logon also. I double-checked my username/passwords as well trying to actually login from the web and with two...
5
2386
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 still didn't work. Any ideas?? 1. In IIS console, right click the virtual directory 2. click directory security tab 3. click edit button on anonymous access 4. click browse button
18
2714
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 the correct password/username before appear an error message) thanks before..
1
4458
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 any best practice that can be followed on failed login attempts. Any help would be greatly helpful. Thanks, Dharmesh
17
9590
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 in the MySQL database from 0 to 1. If it remains 0 the user cannot login in. What I want to do, is set it up so if the password is wrong say 5 times then this activiation number is updated and changed to 0 again. How would be best to do this? If...
3
6576
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 failed attempts, etc. Can anyone tell me how to make this happen? How do I count the number of times a button us clicked? Thank you.
1
2997
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
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7333
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6167
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4158
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2731
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 we have to send another system
2
1957
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1620
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.