Very simple but im having a brain fart please help
Ok i am making the end user have to enter a password and limit them to the ammount of times they have to enter a password. I have it working where if they enter the wrong password it will not let them access the application. for example
Code:
Private Sub Command1_Click()
Dim i As Integer
i = i + 1
If Text1.Text = "Password" Then
MsgBox "Yay :)", vbCritical
Else
If i = 3 Then
End
Else
MsgBox "Boo! :(", vbCritical
Label1.Caption = i
End If
End If
End Sub
what do i have wrong?
Re: Very simple but im having a brain fart please help
rather than Dim i as Integer use Static i as Integer and it's value will be remembered over subsequent calls.
Try to avoid using End, Unload Me is better. For an explanation consult the FAQ
Re: Very simple but im having a brain fart please help
If you want to limit to certain number of attempts then declare integer variable locally as Static or move declaration to a general section:
Static i As Integer
Re: Very simple but im having a brain fart please help
It probably doesn't matter much for your purposes but maybe it will for someone who reads this in the future. Storing a password (or any sensitive text) as a string literal in your source code isn't very secure. Someone can find the password by passing your executable through a hex viewer. A potentially more secure solution is to store, say, an MD5 hash of the string you actually want and compare hashes to test for equality. This has problems too, but it takes significantly more work to overcome.
Re: Very simple but im having a brain fart please help
Quote:
Originally Posted by
jemidiah
It probably doesn't matter much for your purposes but maybe it will for someone who reads this in the future. Storing a password (or any sensitive text) as a string literal in your source code isn't very secure. Someone can find the password by passing your executable through a hex viewer. A potentially more secure solution is to store, say, an MD5 hash of the string you actually want and compare hashes to test for equality. This has problems too, but it takes significantly more work to overcome.
Actually you really should use a salted hash as md5 is pretty easy to crack.
Re: Very simple but im having a brain fart please help
That's a good point, especially for passwords which are often susceptible to dictionary attacks.
Re: Very simple but im having a brain fart please help
Quote:
Originally Posted by
jemidiah
...Storing a password (or any sensitive text) as a string literal in your source code isn't very secure. Someone can find the password by passing your executable through a hex viewer...
Don't even need that. Open an exe in NotePad and you can find what you are looking for. Stored text stands out pretty well.
Re: Very simple but im having a brain fart please help
Milk and Rhino sorted it out for you, Charlie. Here is what your code should be if you want your function to remember the false attemps:
Code:
Private Sub Command1_Click()
'Dim i As Integer
STATIC i As Integer
i = i + 1
If Text1.Text = "Password" Then
MsgBox "Yay :)", vbCritical
ElseIf i<3 Then
MsgBox "Wrong attempt. Try again.", vbInformation
Else
MsgBox "Boo! :(", vbCritical
End If
Label1.Caption = Cstr(i)
End Sub