Advertisement
Guest User

Code

a guest
Dec 23rd, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. #include "mysql_connection.h"
  2.  
  3. #include <cppconn/driver.h>
  4. #include <cppconn/exception.h>
  5. #include <cppconn/resultset.h>
  6. #include <cppconn/statement.h>
  7. int main()
  8. {
  9. string Username;
  10. string Pass;
  11.  
  12. try
  13. {
  14.  
  15.  
  16.  
  17. sql::ResultSet *res;
  18. sql::ResultSet *res2;
  19. sql::Driver *driver;
  20. sql::Connection *con;
  21. sql::Statement *stmt;
  22.  
  23.  
  24. bool loggingin = true;
  25. driver = get_driver_instance();
  26. con = driver->connect([inserpassword stuff]);
  27.  
  28. con->setSchema("sql2271023");
  29. stmt = con->createStatement();
  30. res = NULL;
  31. res2 = NULL;
  32. while (loggingin) {
  33. printf("Please Type Your Username: \n >>");
  34. cin >> Username;
  35. printf("Please Type Your Password: \n >>");
  36. cin >> Pass;
  37. stmt->executeQuery("SELECT Password WHERE UserName = '" + Username + "'"); -- at this line Unhandled exception at 0x00007FF89BA1A388 in SecretProject.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x000000CECFAF7220
  38. res = stmt->executeQuery("SELECT Password WHERE UserName = '" + Username + "'");
  39. res2 = stmt->executeQuery("SELECT HWID WHERE UserName = '" + Username + "'");
  40.  
  41.  
  42.  
  43. res = stmt->executeQuery("Get Password where Username = '" + Username + "'");
  44.  
  45. string password = res->getString(1);
  46. res2->next();
  47.  
  48. while (res->next()) {
  49. if (res->getRow() == 0 || password != Pass) {
  50. printf("Username or Password Wrong");
  51.  
  52. }
  53. else {
  54.  
  55. if (res2->getString(1) != getHWID()) {
  56. exit(1);
  57.  
  58. }
  59. else {
  60. loggingin = false;
  61.  
  62.  
  63. }
  64.  
  65. }
  66.  
  67. break;
  68. }
  69.  
  70.  
  71. }
  72. delete con;
  73. delete res;
  74. delete res2;
  75.  
  76. delete stmt;
  77.  
  78. }catch(sql::SQLException &e)
  79. {
  80. cout << "# ERR: SQLException in " << __FILE__;
  81. cout << "(" << __FUNCTION__ << ") on line "<< __LINE__ << endl;
  82. cout << "# ERR: " << e.what();
  83. cout << " (MySQL error code: " << e.getErrorCode();
  84. cout << ", SQLState: " << e.getSQLState() << " )" << endl;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement