Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---- headers.h -----
- #include <QtSql>
- #include <QSqlDatabase>
- #include <QCryptographicHash>
- #include <QByteArray>
- QSqlDatabase db =QSqlDatabase::addDatabase("QMYSQL");
- void dbconnect()
- {
- //QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
- db.setHostName("xxx.xxx.xxx");
- db.setDatabaseName("xxxxx");
- db.setUserName("db_user");
- db.setPassword("xxxxx");
- }
- void closeDB()
- {
- QSqlDatabase::removeDatabase("QMYSQL");
- }
- ----------------------------
- login.cpp
- -----
- #include "headers.h"
- #include "logindialog.h"
- #include <QtGui>
- loginDialog::loginDialog(QWidget *parent)
- : QWidget(parent)
- {
- ui.setupUi(this);
- }
- loginDialog::~loginDialog()
- {
- }
- void loginDialog::showMainWindow()
- {
- }
- void loginDialog::tryLogin()
- {
- dbconnect();
- QString uname = ui.username->text();
- QString passwd = ui.passwd->text();
- QCryptographicHash *pwhash = new QCryptographicHash(QCryptographicHash::Md5);
- QByteArray passwdstr = ui.passwd->text().toStdString().c_str();
- pwhash->addData(passwdstr);
- QByteArray string1 = pwhash->result();
- //QMessageBox::information(this, "testi", uname + " " + string1);
- if(db.open())
- {
- QSqlQuery query("Select username from admin WHERE username='"+uname+"' AND password='"+string1+"'");
- query.exec();
- while(query.next())
- {
- QMessageBox::information(this, "Testi", query.value(0).toString());
- }
- qDebug() << query.lastError();
- } else {
- qDebug() << "Error";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement