- bool CheckCredentials(LocalUser* user)
- {
- std::string thisquery = freeformquery;
- std::string safepass = user->password;
- std::string safegecos = user->fullname;
-
- /* Search and replace the escaped nick and escaped pass into the query */
-
- SearchAndReplace(safepass, std::string("\""), std::string("\\\""));
- SearchAndReplace(safegecos, std::string("\""), std::string("\\\""));
-
- SearchAndReplace(thisquery, std::string("$nick"), user->nick);
- SearchAndReplace(thisquery, std::string("$pass"), safepass);
- SearchAndReplace(thisquery, std::string("$host"), user->host);
- SearchAndReplace(thisquery, std::string("$ip"), std::string(user->GetIPString()));
- SearchAndReplace(thisquery, std::string("$gecos"), safegecos);
- SearchAndReplace(thisquery, std::string("$ident"), user->ident);
- SearchAndReplace(thisquery, std::string("$server"), std::string(user->server));
- SearchAndReplace(thisquery, std::string("$uuid"), user->uuid);
-
- HashProvider* md5 = ServerInstance->Modules->FindDataService<HashProvider>("hash/md5");
- if (md5)
- SearchAndReplace(thisquery, std::string("$md5pass"), md5->hexsum(user->password));
-
- HashProvider* sha256 = ServerInstance->Modules->FindDataService<HashProvider>("hash/sha256");
- if (sha256)
- SearchAndReplace(thisquery, std::string("$sha256pass"), sha256->hexsum(user->password));
-
- /* Build the query */
- SQLrequest req = SQLrequest(this, SQLprovider, databaseid, SQLquery(thisquery));
-
- req.Send();
- /* When we get the query response from the service provider we will be given an ID to play with,
- * just an ID number which is unique to this query. We need a way of associating that ID with a User
- * so we insert it into a map mapping the IDs to users.
- * Thankfully m_sqlutils provides this, it will associate a ID with a user or channel, and if the user quits it removes the
- * association. This means that if the user quits during a query we will just get a failed lookup from m_sqlutils - telling
- * us to discard the query.
- */
- AssociateUser(this, SQLutils, req.id, user).Send();
-
- return true;
- }