Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trapping too many failed attempts at password entry

Status
Not open for further replies.

idd

Programmer
Apr 19, 2002
165
GB
I'm sure someone will have a simple solution to this.

I am using Access 97,

I want to use a password system on my database. What I have done is create a table with a single field and that field is the password. There will only be one entry in this table.

On my form i have a text box which is bound to the password table so it displays the one record in there. The textbox is not visible. this textbox is called txt_TruePW

I have another textbox on the form which the user uses to enter in their password. If the password they enter matches the password in the textbox txt_TruePW then it opens the Main Menu.

if it doesnt then it pops up a message box saying the usual incorrect entry stuff. what I would like is that if the user has three wrong attempts then it tells them too many wrong attempts and kicks them off the system.

I have the first part sorted where if the password is correct then it lets them through. But if the password is wrong it stop the user after 3 attempts.

here is the code that I am using



Dim stDocName As String
Dim attempt As Integer


attempt = 0

If Me.Text1.Value = Me.txt_TruePW.Value Then
stDocName = "FRM_ToDo"
DoCmd.OpenForm stDocName
DoCmd.Close acForm, "FRM_Pword", acSavePrompt
Else
If attempt < 3 Then
MsgBox &quot;Incorrect password&quot; & (Chr(13)) & (Chr(13)) & &quot;Remember passwords are case sensitive,&quot; & (Chr(13)) & _
&quot;ensure that you are entering the password correctly&quot;, vbExclamation, &quot;HP Prompt Security&quot;
attempt = attempt + 1

Else
If attempt = 3 Then
MsgBox &quot;Too many failed attempts&quot;, vbCritical, &quot;Mission Aborted&quot;
docmd.quit
End If
End If
End If



Thanx in advance

Iddris
 
You forgot the End If statements, it seems.

Try making 3 separate if statements with End Ifs and you should be fine, I think. Catapultam habeo. Nisi pecuniam omnem mihi dabis, ad caput tuum saxum immane mittam.
 
If tried that and many other variations but still no joy.

still need help
 
I think you need to set attempt to 0 when you load the form.

If you have attempt = 0 when you click on the button it'll reset attempt to 0. Catapultam habeo. Nisi pecuniam omnem mihi dabis, ad caput tuum saxum immane mittam.
 
Try this :

Private Sub Text0_BeforeUpdate(Cancel As Integer)

Static attempt As Integer
Dim stdocname As String

If Text1 = txt_truePW Then
stdocname = &quot;frmTO_DO&quot;
DoCmd.OpenForm stdocname
DoCmd.Close acForm, Me.name
Else
attempt = attempt + 1
Call MsgBox(&quot;Wrong password.&quot;, vbExclamation)
End If

If attempt = 3 Then
Call MsgBox(&quot;Get out sucker!&quot;, vbCritical)
DoCmd.Quit
End If

End Sub

I hope this helps.
 
Might I suggest that the you add afield to the record containing the password and place the failed number of attempts in it. If the password is good it is reset to zero. That way, if he fails three times, he can't just back out, come in again and try another 3 times.
 
Grnzbra

its a good suggestion but i'm not storing or using user names, if I implemented your suggestion it would mean that if someone who was not supposed to use the system tried accessing it and entered the wrong password and got it wrong three times then that would mean no-one else would be able to use the system.

i think..

iddris
 
I think Cabal's idea is good - setting attempt as a static variable. combine that with mine, to set attempt to 0 when loading up the form, and you've got something going :) Catapultam habeo. Nisi pecuniam omnem mihi dabis, ad caput tuum saxum immane mittam.
 
Cabals idea work fine as it is.

it doesn't require me to set attempt to 0 when the form loads up.
 
Great then ;) I was useless here but I learned a lot. Catapultam habeo. Nisi pecuniam omnem mihi dabis, ad caput tuum saxum immane mittam.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top