|
-
Feb 4th, 2011, 09:30 AM
#1
Thread Starter
Lively Member
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?
If i help please rate me
If Your Question Has Been Answered Please Mark Your Thread As RESOLVED So Other People (ME) Can Use The Helpful Tips As Well , Thanks
New to VBForums? It's ok i was also at one point n time and i am still learning and meeting new people everyday check out the FAQ Section it is very helpful
Sleep brings release and the hope of a new day - Killswitch Engage
-
Feb 4th, 2011, 09:38 AM
#2
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
-
Feb 4th, 2011, 09:39 AM
#3
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
-
Feb 4th, 2011, 02:55 PM
#4
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.
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
-
Feb 4th, 2011, 03:27 PM
#5
Re: Very simple but im having a brain fart please help
 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.
-
Feb 4th, 2011, 04:10 PM
#6
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.
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
-
Feb 4th, 2011, 05:24 PM
#7
Re: Very simple but im having a brain fart please help
 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.
-
Feb 5th, 2011, 04:21 AM
#8
Hyperactive Member
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
If your problem is solved, then drag down the Thread Tools and mark your thread as Resolved.
If I helped you solve your problem, inflate some air into my ego by rating my post and adding a comment too.
For notorious issues (elaborate yourself) contact me via PM. I don't answer them in the forums EVER.
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
|