Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <strings.h>
  7.  
  8. #include <cgicc/CgiDefs.h>
  9. #include <cgicc/Cgicc.h>
  10. #include <cgicc/HTTPHTMLHeader.h>
  11. #include <cgicc/HTMLClasses.h>
  12. #include <sqlite3.h>
  13.  
  14. using namespace std;
  15. using namespace cgicc;
  16.  
  17. string userName;
  18. string passWord;
  19. string sortCode;
  20.  
  21. string userTest;
  22. // getting user input from form //
  23. // compares user input to database //
  24.  
  25. //TODO create and send session ID to accounts page?
  26. //
  27.  
  28.  
  29.  
  30. static int callback(void *data, int argc, char **argv, char **azColName)
  31. {
  32. int i;
  33. cout << " : " << (const char*)data;
  34. cout << " " << endl;
  35.  
  36.  
  37. if (userName == argv[1] && passWord == argv[2] && sortCode == argv[3]){
  38. cout << " MATCH TO DATABASE " << endl;
  39. //flag to send cookie
  40. cout << userName << passWord << sortCode << endl;
  41. }/* else{
  42. cout << " NO USER EXISTS" << endl;
  43. }*/
  44.  
  45. cout << " " << endl;
  46. return 0;
  47. }
  48.  
  49. int main()
  50. {
  51.  
  52. sqlite3 *db;
  53. char *errMsg = 0;
  54. int rc;
  55. string sql;
  56. const char* data = "Callback called : ";
  57.  
  58. //Opening the database
  59. rc = sqlite3_open("/usr/lib/cgi-bin/bank.db", &db);
  60.  
  61. //cout<< "USERNAME : " << userName << endl;
  62. //cout <<"PASSWORD : " << passWord << endl;
  63. //cout << " SSID : " << sortCode << endl;
  64. /*
  65. // Setting the cookie information
  66. //cout << "Set-Cookie:UserID = "<< userName << ";\r\n";
  67. //cout << "Set-Cookie:Password = " << passWord << ";\r\n";
  68. //cout << "Set-Cookie:SessionID = " << sortCode << ";\r\n";
  69. //cout << "Set-Cookie:Domain = /index.html;\r\n";
  70. //cout << "Set-Cookie:Path = /account.html;\r\n";
  71.  
  72. */
  73.  
  74. cout << "Content-type:text/html\r\n\r\n";
  75. /*//cout << "Location: /account.html\r\n\r\n" ; */
  76. cout << "<html>\n";
  77. /*//cout << "<meta https-equiv='Refresh' content='3 ; url=/account.html'>" ;*/
  78. cout << "<head>\n";
  79. cout << "<title> WELCOME TO EL BANCO DE NATHAN </title>\n";
  80. cout << "</head>\n";
  81.  
  82. Cgicc formData;
  83. form_iterator fi = formData.getElement("username");
  84.  
  85.  
  86. if(!fi->isEmpty() && fi != (*formData).end())
  87. {
  88. cout << "Username :" << **fi << endl;
  89. userName = **fi ;
  90. }else{
  91. cout << "Nothing entered" << endl;
  92. }
  93. cout << "<br/>\n";
  94.  
  95.  
  96. fi = formData.getElement("password");
  97. if(!fi->isEmpty() && fi != (*formData).end())
  98. {
  99. cout << "Password :" << **fi << endl;
  100. passWord = **fi;
  101. }else{
  102. cout << "Nothing entered" << endl;
  103. }
  104. cout << "<br/>\n";
  105.  
  106. fi = formData.getElement("branch");
  107. if(!fi->isEmpty() && fi !=(*formData).end())
  108. {
  109. cout << "Branch :" << **fi << endl;
  110. sortCode = **fi;
  111. }else{
  112. cout << "Nothing Entered" << endl;
  113. }
  114. cout << "<br/>\n";
  115.  
  116.  
  117. if (rc)
  118. {
  119. cout << "CANNAE OPEN DATABASE" << endl;
  120. return(0);
  121. }else {
  122. cout << "OPENED THE DATABASE" << endl;
  123. }
  124. userTest.append(userName);
  125. cout << "userTest :" << userTest << endl;
  126. sql = "SELECT * FROM BANK WHERE username = '";
  127. sql.append(userTest);
  128. sql.append("'");
  129.  
  130. cout << sql << endl;
  131.  
  132.  
  133. rc = sqlite3_exec(db,sql.c_str(),callback, (void*)data, &errMsg);
  134. if (rc != SQLITE_OK)
  135. {
  136. cout << "SQL HAS ERROR " << errMsg << endl;
  137. sqlite3_free(errMsg);
  138. } else {
  139. cout << "OPERATION COMPLETE" << endl;
  140. }
  141. cout << "<br/>";
  142. cout << "<a href=/account.html> View YOUR Account</a>";
  143. cout << "</body>\n";
  144. cout << "</html>\n";
  145.  
  146. sqlite3_close(db);
  147. return 0;
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement