Results 1 to 7 of 7

Thread: whats wrong with my functions? [resolved]

  1. #1

    Thread Starter
    Frenzied Member ice_531's Avatar
    Join Date
    Aug 2002
    Location
    Sitting w/ Bob Status: -Next -To- Null- Friend: Philip
    Posts
    1,152

    Resolved whats wrong with my functions? [resolved]

    Okay, im not going to go into every aspect of the program but here goes:

    I've written 2 functions on my serverside which checks a username list for a match n if it finds it then it goes to the 2nd function which then checks if the password in the other listbox matches whats in the database aswell.

    now on my client end , its waiting to receive a "failed" , "1" ,or "2" string back... i know the problem lies in my loginCheck1 function. but say that the login fails due to incorrect username it sends failed twice and then a 1 because maybe the password matches..no clue how this happens seeing as how it shouldn't even go to loginCheck2 if check1 doesnt succeed.

    VB Code:
    1. Private Function loginCheck1()
    2. Dim i As Integer
    3. Dim userName As String
    4. Dim IntList As Integer
    5. userName = Text1 'the username attempting to login
    6. For i = 0 To List2.ListCount - 1
    7. If InStr(userName, List2.List(i)) Then ' check database list for username
    8. 'do whatever you need here.....if it finds the name
    9. IntList = i
    10. List3.Text = List3.List(IntList) 'get corresponding pass next to username
    11. loginCheck2 ' send to logincheck2 function to check if password matches too
    12. Exit For 'exit for if found
    13. Else
    14. 'send back message saying incorrect username/password
    15. server.senddata "failed"
    16. End If
    17. Next
    18. End Function
    19.  
    20. Private Function loginCheck2()
    21. Dim strLogin As String
    22. Dim userPass As String
    23. userPass = Text2
    24. 'check to see if the password matches whats in the database under that username
    25. If List3.Text = userPass Then
    26. 'it matches, do stuff here
    27. strLogin = "1"
    28. server.SendData strLogin
    29. List1.AddItem server.RemoteHostIP & " has logged in successfully! at: " & Now
    30. Else
    31. strLogin = "2"
    32. server.SendData strLogin
    33. End If
    34. End Function

    and heres the client end

    VB Code:
    1. Private Sub client_DataArrival(ByVal bytesTotal As Long)
    2. Dim strLogin As String
    3. ' do stuff to verify if login was successful
    4. client.GetData strLogin
    5. Text1.Text = strLogin
    6. If strLogin = "1" Then
    7. MsgBox "You have logged in successfully! Welcome to the Valeo Chat System...", vbInformation, "Valeo System"
    8. budlist.Show 'since they've logged in correctly, load buddylist lol =D
    9. ElseIf strLogin = "2" Then
    10. MsgBox "Sorry, but your login attempt has failed due to an incorrect username/password!", vbCritical, "Login Failed"
    11. client.Close ' close connection to server
    12. End If
    13. End Sub

    im sure im just not seeing something obvious though,
    Last edited by ice_531; Dec 30th, 2004 at 01:51 AM.
    :::`DISCLAIMER`:::
    Do NOT take anything i have posted to be truthful in any way, shape or form.
    Thank You!

    --------------------------------
    "Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
    "Finaly I can look as gay as I want..." - NoteMe
    Languages: VB6, BASIC, Java, C#. C++

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: whats wrong with my functions? [waits for reply]

    can't get it to go into function 2 while username dosen't match, but your server.senddata should be outside your for loop and sent only if the loop completes without match, (if it matches on last list item of 600 you'd get 599 failed messages first, then a 1


    Code:
    Private Function loginCheck1()
    Dim i As Integer
    Dim userName As String
    Dim IntList As Integer
    userName = Text1 'the username attempting to login
    For i = 0 To List2.ListCount - 1
        If InStr(userName, List2.List(i)) Then ' check database list for username
            'do whatever you need here.....if it finds the name
            IntList = i
            List3.Text = List3.List(IntList) 'get corresponding pass next to username
            loginCheck2 ' send to logincheck2 function to check if password matches too
            Exit For 'exit for if found
    '        Else
    ''send back message saying incorrect username/password
    ''server.senddata "failed" End If
        End If
     Next
       MsgBox "failed"
    End Function

  3. #3

    Thread Starter
    Frenzied Member ice_531's Avatar
    Join Date
    Aug 2002
    Location
    Sitting w/ Bob Status: -Next -To- Null- Friend: Philip
    Posts
    1,152

    Re: whats wrong with my functions? [waits for reply]

    I've moved stuff around so many times...
    When the senddata is outside of the loop it does fix part of the problem also i added an exitfor with the senddata with it inside the loop...both of these return the same type of results

    when the username and password indeed do match with username and password in lists then it sends a 2 for some reason and nothing else...so i do at least get a msgbox, just the wrong msgbox.

    when i login with a name and pwd which isnt in the db it sends nothing back.

    where shall i move stuff around in the check1 function?
    :::`DISCLAIMER`:::
    Do NOT take anything i have posted to be truthful in any way, shape or form.
    Thank You!

    --------------------------------
    "Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
    "Finaly I can look as gay as I want..." - NoteMe
    Languages: VB6, BASIC, Java, C#. C++

  4. #4
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: whats wrong with my functions? [waits for reply]

    Indeed.
    Your loop sends a "failed" every time it finds no match.
    Then, if it finds a match, it will start logincheck2.

    What you could do is declare a boolean and let the loop make it true if it finds a match.
    Then, outside the loop, you make another if-then that sends a "failed" if the boolean is false.

    If it did find a match then logincheck2 would have sent something else before exiting the loop.

  5. #5

    Thread Starter
    Frenzied Member ice_531's Avatar
    Join Date
    Aug 2002
    Location
    Sitting w/ Bob Status: -Next -To- Null- Friend: Philip
    Posts
    1,152

    Re: whats wrong with my functions? [waits for reply]

    Quote Originally Posted by jeroen79
    Indeed.
    Your loop sends a "failed" every time it finds no match.
    Then, if it finds a match, it will start logincheck2.

    What you could do is declare a boolean and let the loop make it true if it finds a match.
    Then, outside the loop, you make another if-then that sends a "failed" if the boolean is false.

    If it did find a match then logincheck2 would have sent something else before exiting the loop.
    ahh im such an idiot , i remember doing that in the past for a similiar type function to function method.
    let me try then ill post
    :::`DISCLAIMER`:::
    Do NOT take anything i have posted to be truthful in any way, shape or form.
    Thank You!

    --------------------------------
    "Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
    "Finaly I can look as gay as I want..." - NoteMe
    Languages: VB6, BASIC, Java, C#. C++

  6. #6

    Thread Starter
    Frenzied Member ice_531's Avatar
    Join Date
    Aug 2002
    Location
    Sitting w/ Bob Status: -Next -To- Null- Friend: Philip
    Posts
    1,152

    Re: whats wrong with my functions? [waits for reply]

    VB Code:
    1. Private Function loginCheck1()
    2. Dim i As Integer
    3. Dim userName As String
    4. Dim bFound As Boolean
    5. Dim IntList As Integer
    6. userName = Text1 'the username attempting to login
    7. For i = 0 To List2.ListCount - 1
    8. If InStr(userName, List2.List(i)) Then ' check database list for username
    9. 'do whatever you need here.....if it finds the name
    10. bFound = True
    11. IntList = i
    12. List3.Text = List3.List(IntList) 'get corresponding pass next to username
    13. loginCheck2 ' send to logincheck2 function to check if password matches too
    14. Exit For 'exit for if found
    15. End If
    16. Next
    17. If Not bFound Then
    18.     server.SendData "2" 'send the failed attempt
    19. End If
    20. End Function

    working so far on all of my test attempts.

    Thanks for everyones input
    :::`DISCLAIMER`:::
    Do NOT take anything i have posted to be truthful in any way, shape or form.
    Thank You!

    --------------------------------
    "Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
    "Finaly I can look as gay as I want..." - NoteMe
    Languages: VB6, BASIC, Java, C#. C++

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: whats wrong with my functions? [resolved]

    instead of the boolean you can replace exit for , with exit sub as you are finised ther anyway

    p.



    oops exit function

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