|
-
Dec 30th, 2004, 12:40 AM
#1
Thread Starter
Frenzied Member
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:
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
Next
End Function
Private Function loginCheck2()
Dim strLogin As String
Dim userPass As String
userPass = Text2
'check to see if the password matches whats in the database under that username
If List3.Text = userPass Then
'it matches, do stuff here
strLogin = "1"
server.SendData strLogin
List1.AddItem server.RemoteHostIP & " has logged in successfully! at: " & Now
Else
strLogin = "2"
server.SendData strLogin
End If
End Function
and heres the client end
VB Code:
Private Sub client_DataArrival(ByVal bytesTotal As Long)
Dim strLogin As String
' do stuff to verify if login was successful
client.GetData strLogin
Text1.Text = strLogin
If strLogin = "1" Then
MsgBox "You have logged in successfully! Welcome to the Valeo Chat System...", vbInformation, "Valeo System"
budlist.Show 'since they've logged in correctly, load buddylist lol =D
ElseIf strLogin = "2" Then
MsgBox "Sorry, but your login attempt has failed due to an incorrect username/password!", vbCritical, "Login Failed"
client.Close ' close connection to server
End If
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++
-
Dec 30th, 2004, 01:25 AM
#2
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
-
Dec 30th, 2004, 01:34 AM
#3
Thread Starter
Frenzied Member
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++
-
Dec 30th, 2004, 01:40 AM
#4
Frenzied Member
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.
-
Dec 30th, 2004, 01:42 AM
#5
Thread Starter
Frenzied Member
Re: whats wrong with my functions? [waits for reply]
 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++
-
Dec 30th, 2004, 01:50 AM
#6
Thread Starter
Frenzied Member
Re: whats wrong with my functions? [waits for reply]
VB Code:
Private Function loginCheck1()
Dim i As Integer
Dim userName As String
Dim bFound As Boolean
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
bFound = True
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
End If
Next
If Not bFound Then
server.SendData "2" 'send the failed attempt
End If
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++
-
Dec 30th, 2004, 02:04 AM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|