How do I refuse access after three incorrect passwords?
Tuesday 13 March 2001 9:02 AM
I am just learning VB, I am doing a project that I need to set up an
opening screen that requests a password and after three failed attempts
will exit the program. Do you have any suggestions for me? Should I be
using a nested IF? Look forward to hearing from you as this has got me
totally confused and I can't find an example in any of my books.
Firstly, create a form that looks similar to this:
The password textbox needs to have the PasswordChar property
set to '*'.
In the General/Declarations section of the code window, you
will need to declare an Integer variable, which will count how many attempts the
user has made. When the user clicks on the OK button, the code will check
to see if the correct password has been entered. If not, the value of the
Var1 variable will be incremented by 1. If the user enters three incorrect
passwords, a message box will appear saying that the program will terminate,
which it does afterwards.
Var1 As Integer
If Text2.Text <>
Select Case Var1
Case Is <= 2
MsgBox "The password is
Var1 = Var1 + 1
MsgBox "You have entered the wrong
password too many times, you are now locked out. Please contact
your system administrator. The program will now terminate.",
vbCritical, "Locked Out"
MsgBox "(The correct password was
I am trying to get my program to exit after 3 failed password attempts. I have tried the code above and can't get it to work. It doesn't seem to count the number of attempts. Any ideas?
Did you declare the variable in the General/Declarations
section? Another way of doing it is to declare it in the
Command1_Click event using the Static statement. That way the
variables value will be retained for as long as the code is running.
Hello. I am having trouble in disabling a button. What it is, the program asks the user to input a password a few times. On failing to input the correct password on the attempts given, rather than closing the program, the button the user clicked is disabled. Can you please help. Bye.