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);
*/
