How do I refuse access after three incorrect passwords?
Question
From:
MIKE SMITH
Date:
Tuesday 13 March 2001 9:02 AM
Subject:
Nested IF
Question:
Good Day!!
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.
Thanx,
Mike
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.
Dim
Var1 As Integer
Private Sub
Command1_Click()
If Text2.Text <>
"hello" Then
Select Case Var1
Case Is <= 2
MsgBox "The password is
incorrect", vbExclamation,
"Incorrect Password"
Var1 = Var1 + 1
Case Else
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"
Unload Me
End Select
Else
MsgBox "(The correct password was
entered)"
End If
End Sub
Hi
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?
Thanks, Alison
Reply:
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.
what coding would you put in there if you wanted the program to switch to another form and close the login box, only if the password is correct?
thanks grean.
Reply:
Replace the line:
MsgBox "(The correct password was
entered)"
with:
Unload Me 'Unload the login form
Form2.Show 'Replace Form2 with whatever form you
want to show
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.
how to set the password before writing this program?
Reply:
The above program is just an example of how to stop the user from
entering the program if they input three incorrect passwords. The
password is set in the third line:
If Text2.Text <>
"hello" Then
Where the password is 'hello'. In reality, passwords can be
hard-coded in the executable or anywhere else e.g. an external file.
Martin Allen 1999 - 2012. Last updated
Friday 05 October 2012 06:28:38 PM +0100.