2013-11-28 63 views
0
listener = New TcpListener(System.Net.IPAddress.Any, portconnect) 
    listener.Start() 
    client = listener.AcceptTcpClient 
    loginInfo = receivedata() 
    Dim array() As String 
    array = loginInfo.Split("|") 
    username = array(0) 
    pass = array(1) 

信息客户端发送到服务器是logininfo。我将logininfo输入用户名和密码。从客户端到服务器vb.net获取实际字符串

Public Function authentication(ByVal user As String, ByVal pass As String) As Boolean 
     Dim authentica As Boolean = False 
     Dim con As New OleDbConnection 
    Try 
     con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & " data source= " & Application.StartupPath & "\" & dataName 

     Dim myCommand As OleDbCommand = con.CreateCommand() 
     Dim sqlstr As String = "" 
     sqlstr = "Select password from tbusers where Username = " & "'" & user & "'" 
     myCommand.CommandText = sqlstr 
     con.Open() 
     Dim passw As String 
     passw = myCommand.ExecuteScalar() 
     con.Close() 
     If pass = passw Then 
      authentica = True 
     End If 

    Catch ex As Exception 
     MsgBox(ex.ToString) 
    End Try 
    Return authentica 
End Function 

问题是:If pass = passw Then authentica = True End If 百达返回false。 请帮忙

+0

没有兄弟,我认为,当客户端发送数据时,数据被封装。调试,用户是用户名和newstr =“用户名”。布尔用户= newstr,它返回false –

+0

请显示你已有的代码不工作 –

回答

1

如果管道字符'|'始终分隔的用户名和密码,分裂:

Dim str As String = "username|password" 
Dim splitString() As String = str.Split("|") 
Dim userName As String = splitString(0) 
Dim password As String = splitString(1) 

至于你提到如果用户名不同的长度(因为它最有可能!),你将需要的东西不断成为分裂的基础。

但是,最好将用户名和密码分开,以便它们可以独立访问。

+0

这不是我的问题兄弟。 –

+2

什么不是你的问题?如果我提供的内容不适合,请更新您的问题并提供一些代码,以显示已经建议的不工作。 – Ric

+0

当您检查pass = passw时,是否看到调试器中的值是否相同?可能是whitepsace或区分大小写的问题 – Ric

1

可以使用Split function

​​

这似乎是一个坏主意,用这种方式发送这些。例如:如果密码包含管道字符会发生什么?

+0

对包含管道的密码是真实的!麻烦会随之而来.. – Ric

+0

然后,密码中通常不允许使用特殊字符吗? –

+0

问题是Logininfo服务器接收是否正确。我获得用户名并传递正确。但是当我检查长度传球时,它的值是8185。我不会不知道为什么 –

相关问题