0

I am making registration/login form with qt c++ saving registration information in mysql password is hashed by md5 also I've tried sha256 same there, so main problem it saves password hashed and I've got no problem with that but when i'm comparing it in login window it doesn't compares and password wrong message appears. without hashing everything works fine, with hashing checking problem. Thanks for help))

if (db.open()) {
    QString email = ui->email->text();
    QString password = QString("%1").arg(QString(QCryptographicHash::hash(ui->password->text().toUtf8(),QCryptographicHash::Md5).toHex()));

    // Insert Query
    QSqlQuery query(QSqlDatabase::database("MyConnection"));
    query.prepare("SELECT * FROM users WHERE email = :email AND password = :password");
    query.bindValue(":email", email);
    query.bindValue(":password", password);

    if (!query.exec()) {
        QMessageBox::information(this,"Failed","Error please try again");
    }
    else {
        QString emailLog = query.value(1).toString();
        QString passwordLog = query.value(4).toString();

        if (query.next()) {
            QMessageBox::information(this,"SUCCESS","SUCCESS");
            ui->plstryagain->close();
            db.close();
        } else {
            QMessageBox::information(this,"Wrong","Wrong Password try again");
            ui->plstryagain->show();
            db.close();
        }
    }
}
else {
    QMessageBox::information(this, "Database Error", "Can't Connect To Database");
}
pushkin
  • 9,575
  • 15
  • 51
  • 95

0 Answers0