I am writing code for a login form that prompts the user for a user ID and password. I am trying to create an incrementing memvar that counts the number of times a user enters an incorrect password. If an incorrect password is entered 3 times, I want the application to close. Here is my code:
LOCAL cUserNumber, cPassword, cUserLevelID, nCount
USE ActSysData!User
cUserNumber = ThisForm.txtUserNumber.Value
cPassword = ThisForm.txtPassword.Value
**Check to make sure user entered a user number and password
IF ISBLANK(m.cUserNumber) OR ISBLANK(m.cPassword) THEN
MESSAGEBOX("Please enter a valid User Number and Password")
RETURN .F. && early exit
ELSE && Search table and make sure usernumber and password are valid
SET ORDER TO 3
SEEK m.cUserNumber
IF NOT FOUND() THEN
MESSAGEBOX("You have entered an invalid User Number")
ELSE && verify that password is correct
IF m.cPassword <> password then
nCount = nCount + 1
IF nCount >= 3 then
QUIT
ENDIF
MESSAGEBOX ("You have entered and invalid Password")
ThisForm.TxtPassword.value = ""
thisform.txtPassword.SetFocus
RETURN .F. && early exit
EndIF
ENDIF
ENDIF
The problem is with nCount. If I don't give it a value when I declare it I get a data-type mismatch error. If I do give it a value then everytime the code is run it resets the value back to it's original state. I've tried For...EndFor, but don't fully understand how to control it. For example
I tried:
FOR i = 1 to 3
IF i >= 3 then
QUIT
ENDIF
EXIT
ENDFOR
but it just keeps looping until 'i' does = 3 and then closes the application, even though the password is only entered incorrectly 1 time.
Thanks in advance for your help.
-Kevin
LOCAL cUserNumber, cPassword, cUserLevelID, nCount
USE ActSysData!User
cUserNumber = ThisForm.txtUserNumber.Value
cPassword = ThisForm.txtPassword.Value
**Check to make sure user entered a user number and password
IF ISBLANK(m.cUserNumber) OR ISBLANK(m.cPassword) THEN
MESSAGEBOX("Please enter a valid User Number and Password")
RETURN .F. && early exit
ELSE && Search table and make sure usernumber and password are valid
SET ORDER TO 3
SEEK m.cUserNumber
IF NOT FOUND() THEN
MESSAGEBOX("You have entered an invalid User Number")
ELSE && verify that password is correct
IF m.cPassword <> password then
nCount = nCount + 1
IF nCount >= 3 then
QUIT
ENDIF
MESSAGEBOX ("You have entered and invalid Password")
ThisForm.TxtPassword.value = ""
thisform.txtPassword.SetFocus
RETURN .F. && early exit
EndIF
ENDIF
ENDIF
The problem is with nCount. If I don't give it a value when I declare it I get a data-type mismatch error. If I do give it a value then everytime the code is run it resets the value back to it's original state. I've tried For...EndFor, but don't fully understand how to control it. For example
I tried:
FOR i = 1 to 3
IF i >= 3 then
QUIT
ENDIF
EXIT
ENDFOR
but it just keeps looping until 'i' does = 3 and then closes the application, even though the password is only entered incorrectly 1 time.
Thanks in advance for your help.
-Kevin