Results 1 to 5 of 5

Thread: Client-Server program, having problem authenticating the client.

  1. #1
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Client-Server program, having problem authenticating the client.

    Hi there guys, I am developing this client-server program. The client is supposed to login to the server before an operation is conducted by the server. This is not so much a problem but rather its just me trying to find out if there a conventional way of handling this scenario. The client sends the login details to the server in a QByteArray (i.e. using a QTcpSocket) and the server invokes the QTcpServer::incomingConnection() function. Lets assume that my username is "Mr_NiceGuy" and my password is "Happy@#guy", the server receives this data in the following format "NiceGuyHappy@#guy", how does the server split the two string for authentication. I have a few ideas, for example I though of not splitting the string but instead join the username and password from the database into one string and then just match the two strings. But I don't know is this is the tried and tested way of doing this. Thanking you in advance.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Client-Server program, having problem authenticating the client.

    If this is QByteArray simply put byte 0x00 between name and password. Not splitting the string is bad idea because different logins and passwords will give the same result.

  3. #3
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Client-Server program, having problem authenticating the client.

    Thank you for your reply Lesiok. I tried your suggestion, please see the code below. Now the problem is that the password does not get appended for some unknown reason. So, immediately after appending the 0x00 byte the password is also appended but for some reason the server doesn't read it.
    Qt Code:
    1. if(socket->state() == QAbstractSocket::ConnectedState)
    2. {
    3. qDebug() << "Connected to server"<<endl;
    4.  
    5. QChar tempByte = 0x00;
    6. QByteArray dataArr;
    7. dataArr.append(loginDetails.at(0));
    8. dataArr.append(tempByte);
    9. dataArr.append(loginDetails.at(1));
    10. socket->write(dataArr);
    11. }
    To copy to clipboard, switch view to plain text mode 

    Seems to work just fine when I use a different byte like 0xFF, do you perhaps know why this is?
    Last edited by ayanda83; 8th February 2017 at 18:04.

  4. #4
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Client-Server program, having problem authenticating the client.

    Assuming loginDetails.at(0) and (1) have the userid/password that you expect, your sending code looks OK to me. What do you do with the data you receive?
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  5. #5
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Client-Server program, having problem authenticating the client.

    If server is working on standard C string then 0x00 may be a problem.

Similar Threads

  1. Replies: 3
    Last Post: 16th August 2015, 11:32
  2. Replies: 3
    Last Post: 29th January 2014, 12:03
  3. Examples for chat program, server-client?
    By Gokulnathvc in forum Newbie
    Replies: 1
    Last Post: 8th September 2011, 10:53
  4. server-client problem
    By sksingh73 in forum Newbie
    Replies: 2
    Last Post: 3rd July 2010, 07:18
  5. TCP server-client app problem
    By pogostick in forum Newbie
    Replies: 6
    Last Post: 25th January 2010, 08:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.