qt mysql数据库md5密码阻塞问题

时间:2018-11-16 15:58:56

标签: c++ mysql qt md5 sha256

我正在使用qt c ++进行注册/登录,将注册信息保存在mysql密码中,由md5进行了哈希处理,我也在这里尝试过sha256,所以主要问题是它保存了哈希处理后的密码,但是我没有问题我在登录窗口中比较它,它不比较,并且出现密码错误消息。不进行哈希处理,一切正常,存在哈希检查问题。感谢您的帮助))

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");
}

0 个答案:

没有答案