Click here to Skip to main content
15,892,199 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
I am working on a college project . The project is network Banking system. I have designed two programs, one for server(admin) and one for the client(customers). The connection is via TCP sockets. here is a brief description:

When the customer(client) logs in by providing the account number and password correctly, the networkstream object transmits account number properly but this is not the case with passwords. When I extract the password on the server side it is not a valid string to fit into the Sql query for verifying the user details in the database. The password String looks like "abc with a missing closing double quotes. The buffer size is 10025.

Here is the server code:

VB
Public Sub Client_Login()

       networkStream = clientSocket.GetStream()
       Dim bytes(10024) As Byte
       networkStream.Read(bytes, 0, CInt(clientSocket.ReceiveBufferSize))
       ClientID = (Encoding.ASCII.GetString(bytes))
       networkStream.Flush()

       
       networkStream.Read(bytes, 0, CInt(clientSocket.ReceiveBufferSize))
       ClientPassword = (Encoding.ASCII.GetString(bytes))
      networkStream.Flush()
       

       connection = New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;data source= D:\Project(Pritam)\Networking Banking System\ActualDatabase.mdb")
       SQL = "Select * from ClientInfo  where Account_No= " & ClientID & "  and  [Password]='" & ClientPassword & "'"
       command = New OleDbCommand(SQL, connection)
       'Try
       connection.Open()
       reader = command.ExecuteReader()
       reader.Read()

       If reader.HasRows = True Then
           Dim ClientAccountNumber As Integer = reader("Account_No")  'extracts account number from database
           Dim PasswordClient As String = reader("Password")        ' extracts password from database

           If ClientAccountNumber = Val(ClientID) And PasswordClient = (ClientPassword) Then

               server_response = "Successful Login"
               Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(server_response)
               networkStream.Write(sendBytes, 0, sendBytes.Length)
               networkStream.Flush()        


Here is the client code:
VB
Private Sub cmdSignin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSignin.Click

       If txtClientID.Text <> "" And txtClientPassword.Text <> "" Then

           Try

               networkStream = clientSocket.GetStream()
               Dim to_server As Byte() = Encoding.ASCII.GetBytes(txtClientID.Text)
               networkStream.Write(to_server, 0, to_server.Length)
               'networkStream.Flush()

               'Dim client_writer As New StreamWriter(clientSocket.GetStream())
               'client_writer.Write(txtClientPassword.Text)

               to_server = Encoding.ASCII.GetBytes(txtClientPassword.Text)
               networkStream.Write(to_server, 0, to_server.Length)
               networkStream.Flush()

               form_refresh()

               Dim login_Thread As Threading.Thread = New Threading.Thread(AddressOf login_final)
               login_Thread.Start()

           Catch ex As Exception
               MsgBox("Server not found" & vbCrLf & "Contact Administrator", MsgBoxStyle.Critical, "Notice!!")
               Me.Close()
           End Try
       Else


Kindly help me as I've to submit my project very soon, please.

Thanking you in advance

--EDIT kschuler: tried to fix code blocks, bolded the actual question to make it stand out more.
Posted
Updated 9-Mar-11 20:14pm
v3

1 solution

This is due to your buffer being a fixed size. Make it dynamic and it should work fine.

Dim bytes() As Byte
Redim bytes(CInt(clientSocket.ReceiveBufferSize)-1)
networkStream.Read(bytes, 0, CInt(clientSocket.ReceiveBufferSize))



To be fair, I am quite surprised that your two sets of data didn't get merged into a single network packet. That used to happen in VB6, maybe .NET handles packets slightly different
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900