|
-
Nov 29th, 2000, 01:29 AM
#1
Thread Starter
Member
This code is supposed to basically limit the number of attempts a user has at changing the pc password. It is then meant to invoke to unload function. Anyone have any ideas why it isnt working and it is allowing many many tries.
Once the old pwd is correct it does what it is meant to.
It just doesnt unload when the attempts >=3 (which is the limit i set)
Any help is appreciated. This on has me stumpted.
Private Sub cmdchange_Click()
'Record how many attempts have been made.
Static iTries As Integer
'Check the user's password to the one that has been saved.
If MMain.Encrypt(txtOldPassword.Text) = MMain.Password Then
If txtNewPassword.Text = txtConfirm.Text Then
'Save the new password.
MMain.Password = txtNewPassword.Text
MsgBox "Password changed.", vbInformation
Unload Me
Else
iTries = iTries + 1
If iTries >= MAX_TRIES Then
'The user did not enter the password in the allowed number of tries.
Unload Me
Else
MsgBox "Wrong password. Try again.", vbExclamation
End If
'Highlight the old password.
With txtOldPassword
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End With
End If
End If
End Sub
Any hints?
regards
Morpheus.
-
Nov 29th, 2000, 01:46 AM
#2
Addicted Member
Have a look at the part that I marked with "HERE IS YOUR PROBLEM". You count the number of tries after the Else statement. That part will be performed only if the new password does not match the confirm password, and NOT when the user enters an incorrect password. You might want to put an "End If" in front of that "Else".
Code:
Private Sub cmdchange_Click()
'Record how many attempts have been made.
Static iTries As Integer
'Check the user's password to the one that has been saved.
If MMain.Encrypt(txtOldPassword.Text) = MMain.Password Then
If txtNewPassword.Text = txtConfirm.Text Then
'Save the new password.
MMain.Password = txtNewPassword.Text
MsgBox "Password changed.", vbInformation
Unload Me
Else ' *** HERE IS YOUR PROBLEM ***
iTries = iTries + 1
If iTries >= MAX_TRIES Then
'The user did not enter the password in the allowed number of tries.
Unload Me
Else
MsgBox "Wrong password. Try again.", vbExclamation
End If
'Highlight the old password.
With txtOldPassword
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End With
End If
End If
End Sub
Shrog
[Edited by Shrog on 11-29-2000 at 02:02 AM]
-
Nov 29th, 2000, 01:54 AM
#3
Counter reset?
Do you ever reset your counter in case the user wants to change the password a second time?
-
Nov 29th, 2000, 02:01 AM
#4
Thread Starter
Member
Althouh i still can't get that damn code to work. You had me thinking for a minute when you asked about the counter.
The application is designed to run on Win9x and initiate when the GUI kicks in, so the counter will reset itself each time the machine is restarted. It doesnt actualyl record the counts anywhere iother than the cache associated witht he live app.
I added and end if and also looked a little more at structure (Messy) but still to no avail.
Anyone else have any other ideas on how to do the same thing?
regards
M.
-
Nov 29th, 2000, 02:17 AM
#5
Check the lines with the asterisks.
Try it out.
Private Sub cmdchange_Click()
'Record how many attempts have been made.
Static iTries As Integer
'Check the user's password to the one that has been saved.
If MMain.Encrypt(txtOldPassword.Text) = MMain.Password Then
If txtNewPassword.Text = txtConfirm.Text Then
'Save the new password.
MMain.Password = txtNewPassword.Text
MsgBox "Password changed.", vbInformation
Unload Me
endif '<------Add this line ******************
Else
iTries = iTries + 1
If iTries >= MAX_TRIES Then
'The user did not enter the password in the allowed number of tries.
Unload Me
Else
MsgBox "Wrong password. Try again.", vbExclamation
End If
'Highlight the old password.
With txtOldPassword
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End With
End If
' End If 'Kill this line ***********************
End Sub
-
Nov 29th, 2000, 02:27 AM
#6
Addicted Member
Can i suggest debugging the code line by line.
I know i've fixed a lot of problems that way.
-
Nov 29th, 2000, 05:26 AM
#7
Thread Starter
Member
The code now works. Thanks to all who offered tips.
Much appreciated.
M.
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
|