[英]get real string from client to server vb.net
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转换为用户名和密码。
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
Allways返回false。 请帮忙
如果管道字符'|' 总是分开用户名和密码,拆分:
Dim str As String = "username|password"
Dim splitString() As String = str.Split("|")
Dim userName As String = splitString(0)
Dim password As String = splitString(1)
正如您所提到的,如果用户名的长度不同(因为它很可能会!),您将需要一些常量作为拆分的基础。
但是最好还是分开用户名和密码,以便可以独立访问它们。
您可以使用拆分功能
Dim str as String = "username|password"
Debug.writeline("Username is " + str.Split("|"c)(0))
Debug.writeline("Password is " + str.Split("|"c)(1))
以这种方式发送这些似乎是一个坏主意。 例如:如果密码包含管道符,会发生什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.