|
-
May 24th, 2002, 04:28 PM
#1
Thread Starter
Addicted Member
password, 3 times etc
How would I edit this so if a password was entered wrong three times it'll exit the program?
Thanks for any help.
VB Code:
Private Sub cmdLogin_Click()
Dim PassRS As Recordset
Set PassRS = Db.OpenRecordset("Login")
While Not PassRS.EOF And Not LoginOK
If (PassRS.Fields("password").Value = txtPassword.Text) And (PassRS.Fields("Username").Value = cboLogin.Text) Then
LoginOK = True
CurrentUser = PassRS("Username").Value
Else
PassRS.MoveNext
End If
Wend
If LoginOK Then
Beep
frmIntro.Show
frmPassword.Hide
txtPassword = ""
LoginOK = False
Else
Response = MsgBox("Incorrect password", vbRetryCancel + vbCritical, "Access Denied")
If Response = vbRetry Then
txtPassword.SetFocus
txtPassword.SelStart = 0
txtPassword.SelLength = Len(txtPassword.Text)
End If
End If
End Sub
-
May 24th, 2002, 04:41 PM
#2
Frenzied Member
add an integer variable to be a counter
Code:
Private Sub cmdLogin_Click()
Dim Count As Integer <----------
Dim PassRS As Recordset
Count = 0 <------Initialize it to 0
Set PassRS = Db.OpenRecordset("Login")
While Not PassRS.EOF And Not LoginOK
If (PassRS.Fields("password").Value = txtPassword.Text) And (PassRS.Fields("Username").Value = cboLogin.Text) Then
LoginOK = True
CurrentUser = PassRS("Username").Value
Else
PassRS.MoveNext
End If
Wend
If LoginOK Then
Beep
frmIntro.Show
frmPassword.Hide
txtPassword = ""
LoginOK = False
Else
Response = MsgBox("Incorrect password", vbRetryCancel + vbCritical, "Access Denied")
If Response = vbRetry Then
txtPassword.SetFocus
txtPassword.SelStart = 0
txtPassword.SelLength = Len(txtPassword.Text)
Count = Count + 1 <---------Add 1 to Counter
If(Counter > 3) Then <--------When Counter exceeds 3 show Msgbox
MsgBox "3 Invalid Login Attempts...This program will now Close"
End
End If
End If
End If
End Sub
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
May 24th, 2002, 04:43 PM
#3
Thread Starter
Addicted Member
Cheers Memnoch
-
May 24th, 2002, 06:17 PM
#4
Thread Starter
Addicted Member
Hm, weird count isn't going past 1, any ideas?
-
May 24th, 2002, 06:19 PM
#5
Frenzied Member
Change
Dim Count As Integer
to
Static Count As Integer
-
May 24th, 2002, 06:21 PM
#6
Originally posted by Shawn N
Change
Dim Count As Integer
to
Static Count As Integer
What for?
-
May 24th, 2002, 06:25 PM
#7
Originally posted by neilm
Hm, weird count isn't going past 1, any ideas?
Um, in his code he has:
VB Code:
Count = Count + 1
If(Counter > 3) Then
Msgbox
I think if you changed Counter to Count, it should work. This, of course, what you'd run into if you copied Memnoch1207's code.
Oh, and you don't need to change to the static part, either.
Destined
-
May 24th, 2002, 06:26 PM
#8
Frenzied Member
...because when you declare a variable using "Dim" the lifetime of the variable keeps its value only as long as the procedure is running. Once the function exits the memory used by the variable is zeroed out and you have nothing.
Using "Static" will keep make sure the variable holds its data.
-
May 24th, 2002, 06:28 PM
#9
Thread Starter
Addicted Member
Yea, sorry forgot to say I changed that part destined soul.. still stickin to 1 though
<edit> changed dim to static too, odd it should work.. </edit>
-
May 24th, 2002, 06:32 PM
#10
Ah, i didn't bother readin the rest of the code. Yes, it should be static, or else count will be set to 0 everytime they click the button. As well, you'll probably want to add count = 0 for when the login is done correctly (reset it so they can log in later...)
Destined
-
May 24th, 2002, 06:34 PM
#11
VB Code:
Count[b]er[/b] = Count[b]er[/b] + 1 <---------Add 1 to Counter
If(Counter [COLOR=deeppink]=[/COLOR] 3) Then 'Change this to =
MsgBox "3 Invalid Login Attempts...This program will now Close"
End
End If
-
May 24th, 2002, 06:34 PM
#12
Thread Starter
Addicted Member
Here's the code but updated..
VB Code:
Private Sub cmdLogin_Click()
Dim PassRS As Recordset
Static PassCount As Integer
'Initialize count to 0
PassCount = 0
Set PassRS = Db.OpenRecordset("Login")
While Not PassRS.EOF And Not LoginOK
If (PassRS.Fields("password").Value = txtPassword.Text) And (PassRS.Fields("Username").Value = cboLogin.Text) Then
LoginOK = True
CurrentUser = PassRS("Username").Value
Else
PassRS.MoveNext
End If
Wend
If LoginOK Then
Beep
frmIntro.Show
frmPassword.Hide
txtPassword = ""
LoginOK = False
mdiMain.lblLoginTime.Caption = Format$(Now, "H:MM AMPM")
mdiMain.lblUsername.Caption = CurrentUser
mdiMain.timDisplay.Enabled = True
mdiMain.mnuLogoff.Caption = "Log off " & CurrentUser
Else
Response = MsgBox("Incorrect password", vbRetryCancel + vbCritical, "Access Denied")
PassCount = PassCount + 1
MsgBox PassCount
If Response = vbRetry Then
txtPassword.SetFocus
txtPassword.SelStart = 0
txtPassword.SelLength = Len(txtPassword.Text)
'Add 1 to Counter
'PassCount = PassCount + 1
'When Counter exceeds 3 show Msgbox
If PassCount = 3 Then
MsgBox "Three invalid login attempts... this program will now shut down", vbInformation, "Program shutdown"
End
End If
ElseIf Response = vbCancel Then
Unload frmPassword
End
End If
End If
End Sub
-
May 24th, 2002, 06:36 PM
#13
-
May 24th, 2002, 06:47 PM
#14
Thread Starter
Addicted Member
Originally posted by Shawn N
Option Explicit takes care of those little problems.
It gives an error, highlighting Static and the msg says "Invalid outside procedure" when doing that..
-
May 24th, 2002, 07:30 PM
#15
Thread Starter
Addicted Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|