-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQLrequests.cpp
More file actions
170 lines (144 loc) · 4.28 KB
/
SQLrequests.cpp
File metadata and controls
170 lines (144 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <iostream>
#include <memory>
#include "mysql_connection.h"
#include "mysql_driver.h"
#include "mysql_error.h"
#include "cppconn/prepared_statement.h"
using namespace sql::mysql;
using namespace std;
std::map<int, string> passwords;
int InsertMPWD(string id, string pwd)
{
sql::mysql::MySQL_Driver* driver;
sql::Connection *con;
sql::PreparedStatement *stmt;
driver = get_mysql_driver_instance();
con = driver->connect("", "botd", "");
con->setSchema("botd");
string query = "INSERT INTO nsi_users (id, master_password) VALUES (?,?)";
stmt = con->prepareStatement(query);
stmt->setString(1, id);
stmt->setString(2, pwd);
stmt->execute();
delete stmt;
delete con;
return 0;
}
bool CheckLogin(string password, string id)
{
sql::mysql::MySQL_Driver* driver;
sql::Connection* con;
sql::PreparedStatement* stmt;
sql::ResultSet* res;
driver = get_mysql_driver_instance();
con = driver->connect("", "botd", "");
con->setSchema("botd");
string query = "SELECT * FROM nsi_users WHERE id = ? AND master_password = ?";
stmt = con->prepareStatement(query);
stmt->setString(1, id);
stmt->setString(2, password);
res = stmt->executeQuery();
while (res->next())
{
return true;
}
return false;
}
bool CheckIfRegistered(string id)
{
sql::mysql::MySQL_Driver* driver;
sql::Connection* con;
sql::PreparedStatement* stmt;
sql::ResultSet* res;
driver = get_mysql_driver_instance();
con = driver->connect("", "botd", "");
con->setSchema("botd");
string query = "SELECT * FROM nsi_users WHERE id = ?";
stmt = con->prepareStatement(query);
stmt->setString(1, id);
res = stmt->executeQuery();
while (res->next())
{
return true;
}
return false;
}
int InsertPWD(string id, string pwd, string identifier)
{
sql::mysql::MySQL_Driver* driver;
sql::Connection* con;
sql::PreparedStatement* stmt;
driver = get_mysql_driver_instance();
con = driver->connect("", "botd", "");
con->setSchema("botd");
string query = "INSERT INTO passwords (id, password, identifier) VALUES (?,?,?)";
stmt = con->prepareStatement(query);
stmt->setString(1, id);
stmt->setString(2, pwd);
stmt->setString(3, identifier);
stmt->execute();
delete stmt;
delete con;
return 0;
}
bool CheckIfExit(string id, string identifier)
{
sql::mysql::MySQL_Driver* driver;
sql::Connection* con;
sql::PreparedStatement* stmt;
sql::ResultSet* res;
driver = get_mysql_driver_instance();
con = driver->connect("", "botd", "");
con->setSchema("botd");
string query = "SELECT * FROM passwords WHERE id = ? AND identifier = ?";
stmt = con->prepareStatement(query);
stmt->setString(1, id);
stmt->setString(2, identifier);
res = stmt->executeQuery();
while (res->next())
{
return true;
}
return false;
}
int RenamePWD(string id, string identifier, string new_identifier)
{
sql::mysql::MySQL_Driver* driver;
sql::Connection* con;
sql::PreparedStatement* stmt;
driver = get_mysql_driver_instance();
con = driver->connect("", "botd", "");
con->setSchema("botd");
string query = "UPDATE passwords SET identifier = ? WHERE id = ? AND identifier = ?";
stmt = con->prepareStatement(query);
stmt->setString(1, new_identifier);
stmt->setString(2, id);
stmt->setString(3, identifier);
stmt->execute();
delete stmt;
delete con;
return 0;
}
int GetPasswords(string id)
{
sql::mysql::MySQL_Driver* driver;
sql::Connection* con;
sql::PreparedStatement* stmt;
sql::ResultSet* res;
int i = 0;
driver = get_mysql_driver_instance();
con = driver->connect("", "botd", "");
con->setSchema("botd");
string query = "SELECT * FROM passwords WHERE id = ?";
stmt = con->prepareStatement(query);
stmt->setString(1, id);
res = stmt->executeQuery();
while (res->next())
{
string pw = res->getString(2);
string identifier = res->getString(3);
passwords[i] = identifier + "_" + pw;
i++;
}
return 0;
}