Results 1 to 8 of 8

Thread: Very simple but im having a brain fart please help

  1. #1

    Thread Starter
    Lively Member Charlie Stallings's Avatar
    Join Date
    Nov 2009
    Location
    Virginia
    Posts
    118

    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

  2. #2
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    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
    W o t . S i g

  3. #3

  4. #4
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    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.

  5. #5
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Re: Very simple but im having a brain fart please help

    Quote Originally Posted by jemidiah View Post
    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.

  6. #6
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    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.

  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Very simple but im having a brain fart please help

    Quote Originally Posted by jemidiah View Post
    ...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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #8
    Hyperactive Member
    Join Date
    Jan 2006
    Location
    Pakistan
    Posts
    388

    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
  •  



Click Here to Expand Forum to Full Width