简体   繁体   English

从客户端到服务器vb.net获取真正的字符串

[英]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)

Info client send to server is logininfo. 信息客户端发送到服务器的是logininfo。 I slipt logininfo into username and password. 我将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

Problem is: If pass = passw Then authentica = True End If Allways return false. 问题是: If pass = passw Then authentica = True End If Allways返回false。 Please help 请帮忙

If the pipe character '|' 如果管道字符'|' always separates the user name and password, split on that: 总是分开用户名和密码,拆分:

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

As you mentioned if the length of the username differs (as it most likely will!) you will need something constant to be the basis for the split. 正如您所提到的,如果用户名的长度不同(因为它很可能会!),您将需要一些常量作为拆分的基础。

But you are better off separating the username and password anyway so they can be accessed independently. 但是最好还是分开用户名和密码,以便可以独立访问它们。

You can use the Split function 您可以使用拆分功能

Dim str as String = "username|password"

Debug.writeline("Username is " + str.Split("|"c)(0))
Debug.writeline("Password is " + str.Split("|"c)(1))

This seems like a bad idea to send these in this way. 以这种方式发送这些似乎是一个坏主意。 For example: what happens if the password contains the pipe character? 例如:如果密码包含管道符,会发生什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM