I've done this in PHP, but for QT i'm not finding much documentation. I compiled the QMYSQL driver (finally), I'm connected to my local DB and all I need to do now is to compare the user supplied username and password against the database. I have already hashed & salted the password.
This is what I currently have, which is not working. More specifically, it is now saying that anything I enter is valid. Please note, QSqlQuery.lastError() is returning a null string.
I echoed the credentials just before the query is executed, everything is proper. I can't think of what it could be.
query.prepare("SELECT UID, PWD FROM login WHERE UID=? AND PWD=?");
query.addBindValue(username);
query.addBindValue(password);
if(!query.exec())
{
msg.setText(query.lastError().text());
msg.exec();
}
int cols = record.count();
if(cols > 0)
{
msg.setText("Good");
return true;
}
else
{
msg.setText("Bad");
return false;
}
query.prepare("SELECT UID, PWD FROM login WHERE UID=? AND PWD=?");
query.addBindValue(username);
query.addBindValue(password);
if(!query.exec())
{
msg.setText(query.lastError().text());
msg.exec();
}
QSqlRecord record = query.record();
int cols = record.count();
if(cols > 0)
{
msg.setText("Good");
return true;
}
else
{
msg.setText("Bad");
return false;
}
To copy to clipboard, switch view to plain text mode
Bookmarks