PDA

View Full Version : Client-Server program, having problem authenticating the client.



ayanda83
8th February 2017, 16:07
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.

Lesiok
8th February 2017, 17:38
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.

ayanda83
8th February 2017, 17:57
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.
if(socket->state() == QAbstractSocket::ConnectedState)
{
qDebug() << "Connected to server"<<endl;

QChar tempByte = 0x00;
QByteArray dataArr;
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?

jefftee
8th February 2017, 19:28
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?

Lesiok
9th February 2017, 07:05
If server is working on standard C string then 0x00 may be a problem.