errbuff fixed, also moved alphanumeric account check to function in StringUtil

This commit is contained in:
Arthur Ice 2014-07-03 17:18:13 -07:00 committed by Arthur Ice
parent 9c6b538176
commit 20e80ebb92
3 changed files with 17 additions and 7 deletions

View File

@ -384,3 +384,15 @@ std::string EscapeString(const std::string &s) {
return ret;
}
bool isAlphaNumeric(const char *text)
{
for (unsigned int charIndex=0; charIndex<strlen(text); charIndex++) {
if ((text[charIndex] < 'a' || text[charIndex] > 'z') &&
(text[charIndex] < 'A' || text[charIndex] > 'Z') &&
(text[charIndex] < '0' || text[charIndex] > '9'))
return false;
}
return true;
}

View File

@ -51,4 +51,6 @@ char *RemoveApostrophes(const char *s);
std::vector<std::string> SplitString(const std::string &s, char delim);
bool isAlphaNumeric(const char *text);
#endif

View File

@ -801,18 +801,14 @@ uint32 Database::GetAccountIDByChar(uint32 char_id) {
uint32 Database::GetAccountIDByName(const char* accname, int16* status, uint32* lsid) {
char *query = nullptr;
for (unsigned int i=0; i<strlen(accname); i++) {
if ((accname[i] < 'a' || accname[i] > 'z') &&
(accname[i] < 'A' || accname[i] > 'Z') &&
(accname[i] < '0' || accname[i] > '9'))
return 0;
}
if (!isAlphaNumeric(accname))
return 0;
auto results = QueryDatabase(query, MakeAnyLenString(&query, "SELECT id, status, lsaccount_id FROM account WHERE name='%s'", accname));
if (!results.Success())
{
std::cerr << "Error in GetAccountIDByAcc query '" << query << "' " << errbuf << std::endl;
std::cerr << "Error in GetAccountIDByAcc query '" << query << "' " << results.ErrorMessage() << std::endl;
safe_delete_array(query);
return 0;
}