Advertisement
Guest User

Untitled

a guest
Aug 4th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. ---- headers.h -----
  2. #include <QtSql>
  3. #include <QSqlDatabase>
  4.  
  5. #include <QCryptographicHash>
  6. #include <QByteArray>
  7.  
  8. QSqlDatabase db =QSqlDatabase::addDatabase("QMYSQL");
  9.  
  10. void dbconnect()
  11. {
  12.  
  13. //QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
  14. db.setHostName("xxx.xxx.xxx");
  15. db.setDatabaseName("xxxxx");
  16.  
  17. db.setUserName("db_user");
  18. db.setPassword("xxxxx");
  19.  
  20.  
  21.  
  22. }
  23.  
  24. void closeDB()
  25. {
  26. QSqlDatabase::removeDatabase("QMYSQL");
  27. }
  28.  
  29.  
  30. ----------------------------
  31. login.cpp
  32. -----
  33.  
  34. #include "headers.h"
  35. #include "logindialog.h"
  36. #include <QtGui>
  37.  
  38.  
  39. loginDialog::loginDialog(QWidget *parent)
  40. : QWidget(parent)
  41. {
  42. ui.setupUi(this);
  43. }
  44.  
  45. loginDialog::~loginDialog()
  46. {
  47.  
  48. }
  49.  
  50. void loginDialog::showMainWindow()
  51. {
  52.  
  53.  
  54.  
  55. }
  56.  
  57. void loginDialog::tryLogin()
  58. {
  59. dbconnect();
  60.  
  61.  
  62. QString uname = ui.username->text();
  63. QString passwd = ui.passwd->text();
  64.  
  65. QCryptographicHash *pwhash = new QCryptographicHash(QCryptographicHash::Md5);
  66.  
  67. QByteArray passwdstr = ui.passwd->text().toStdString().c_str();
  68.  
  69. pwhash->addData(passwdstr);
  70.  
  71. QByteArray string1 = pwhash->result();
  72. //QMessageBox::information(this, "testi", uname + " " + string1);
  73.  
  74. if(db.open())
  75. {
  76. QSqlQuery query("Select username from admin WHERE username='"+uname+"' AND password='"+string1+"'");
  77.  
  78.  
  79. query.exec();
  80.  
  81. while(query.next())
  82. {
  83. QMessageBox::information(this, "Testi", query.value(0).toString());
  84. }
  85. qDebug() << query.lastError();
  86. } else {
  87. qDebug() << "Error";
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement