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.
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.
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.
Code:
{
qDebug() << "Connected to server"<<endl;
dataArr.append(loginDetails.at(0));
dataArr.append(tempByte);
dataArr.append(loginDetails.at(1));
socket->write(dataArr);
}
Seems to work just fine when I use a different byte like 0xFF, do you perhaps know why this is?
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?
Re: Client-Server program, having problem authenticating the client.
If server is working on standard C string then 0x00 may be a problem.