Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PacketType Server::CheckForLogin(const char * data,int& id, int& firsttime)
- {
- try {
- sql::mysql::MySQL_Driver* driver;
- sql::Connection* con;
- sql::PreparedStatement* pstmt;
- sql::ResultSet* result;
- int pos = 0;
- std::string server;
- std::string username;
- std::string password;
- GetString(server, pos, data);
- GetString(username, pos, data);
- GetString(password, pos, data);
- //Create mysql Connection
- driver = sql::mysql::get_mysql_driver_instance();
- con = driver->connect(cfg.db.host, cfg.db.username, cfg.db.password);
- //Select database
- con->setSchema(server);
- //Create statment and execute orders save retrieved data into Resultset
- pstmt = con->prepareStatement("SELECT password FROM user_acc WHERE username=? LIMIT 1");
- pstmt->setString(1, username);
- pstmt->execute();
- result = pstmt->getResultSet();
- if (result->rowsCount() > 0) {
- if (result->getString("password").asStdString() == password) {
- pstmt = con->prepareStatement("SELECT firsttimelogin,id FROM user_acc WHERE username= ? LIMIT 1");
- pstmt->setString(1, username);
- pstmt->execute();
- result = pstmt->getResultSet();
- firsttime = result->getInt("firsttimelogin");
- id = result->getInt("id");
- return Login_LoginSuccessful;
- }
- else {
- return Login_WrongPassword;
- }
- }
- else {
- return Login_NoSuchUser;
- }
- delete result;
- delete pstmt;
- delete con;
- }catch (sql::SQLException &e) {
- std::string error = "Mysql Error code :" + std::to_string(e.getErrorCode());
- Log(error);
- error = "Mysql State:" + e.getSQLState();
- Log(error);
- return Mysql_Error;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement