Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

MySQL login

Trying to implement a login system, I'm struggling to get it working. I'm using Qt and MySQL - the MySQL link is functioning fine, just can't get the C++ right. I understand that the system will be susceptible to sql injections - I'm fine with that (for now), as my project involves showing progress. Here's the code:

Code
void MainWindow::on_pushButton_login_clicked()
{

   QString enteredUsername = ui->lineEdit_username->text();
   QString enteredPassword = ui->lineEdit_password->text();
   QString username;
   QString password;


   QSqlQuery loginQuery("SELECT * FROM 'logindetails' WHERE studentID='" + enteredUsername + "' AND password='" + enteredPassword + "';");
   if (!username.compare(enteredUsername) && (!password.compare(enteredPassword)))
       QMessageBox::information(this,"Success", "Login information is correct");
   else
       QMessageBox::information(this,"FAIL", "Incorrect login");

/*

   QSqlQuery usernameQuery("SELECT studentID from userinfo.logindetails");
   while (usernameQuery.next()) {
       QString username = usernameQuery.value(0).toString();
       QMessageBox::information(this,"Success",username+ enteredUsername);

   }
   QSqlQuery passwordQuery("SELECT password from userinfo.logindetails");
   while (passwordQuery.next()) {
       QString password = passwordQuery.value(0).toString();
       QMessageBox::information(this,"Success",password+ typeid(password).name()+ enteredPassword+ typeid(enteredPassword).name());

   }

   if (!username.compare(enteredUsername) && (!username.compare(enteredUsername)))
           QMessageBox::information(this,"Success", "Login information is correct");

   else
       QMessageBox::information(this,"Failure", "Login information is incorrect"+username + password);

*/
i think your problem is the single quotes http://doc.qt.io/qt-5/sql-sqlstatements.html
[Image: bitcoin.png] Be Nice For Once 15hVUVz7xA4kazHdk2BuErENGCskVwjYXP
Querying the DB hasn't been the problem, it returns the correct username and password but they check is at fault.
Try strncmp instead, it's both ANSI and Unicode, might be your problem.
(Jan 21, 2018 07:41 AM)ReBeL_1 Wrote:  Querying the DB hasn't been the problem, it returns the correct username and password but they check is at fault.

Hello, ReBeL_1.

I'm unfamiliar with Qt personally, so take what I have to say with a grain of salt, please.

QString seems to be a C-style string. You are using C++.
You could avoid using the C functions and use a std::string in it's place.

Code
QString foo;
std::string myCPPfoo = foo; // Copy the QString into a C++ string

...

if (myCPPfoo == "string contents here") { /* do stuff here */ }

If what Cute Little Girl suggested is true: This will be an easier to read solution to the problem.

Sorry that I can't be of more assistance. 😖
Is there any such thing as a woman of honor, and sincerity?

https://www.PutItOnMute.com/

4K HDR, WDR time-lapsed truck driving videos!


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by optionalMay 21, 2021 08:42 AM 7 310 May 21, 2021 08:42 AM
Last Post: Charger
[C] by MeterpreterJun 27, 2018 09:06 PM 17 519 Jun 27, 2018 09:06 PM
Last Post: Meterpreter
[C] by MeterpreterJun 27, 2018 02:10 AM 0 187 Jun 27, 2018 02:10 AM
Last Post: Meterpreter