mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-28 11:53:11 -07:00
publish username rules in registration failure
This commit is contained in:
@@ -118,24 +118,29 @@ bool Servatrice_DatabaseInterface::execSqlQuery(QSqlQuery *query)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Servatrice_DatabaseInterface::usernameIsValid(const QString &user)
|
||||
bool Servatrice_DatabaseInterface::usernameIsValid(const QString &user, QString & error)
|
||||
{
|
||||
int maxNameLength = settingsCache->value("users/maxnamelength", 12).toInt();
|
||||
int minNameLength = settingsCache->value("users/minnamelength", 6).toInt();
|
||||
int maxNameLength = settingsCache->value("users/maxnamelength", 12).toInt();
|
||||
bool allowLowercase = settingsCache->value("users/allowlowercase", true).toBool();
|
||||
bool allowUppercase = settingsCache->value("users/allowuppercase", true).toBool();
|
||||
bool allowNumerics = settingsCache->value("users/allownumerics", true).toBool();
|
||||
bool allowPunctuationPrefix = settingsCache->value("users/allowpunctuationprefix", false).toBool();
|
||||
QString allowedPunctuation = settingsCache->value("users/allowedpunctuation", "_").toString();
|
||||
error = QString("%1|%2|%3|%4|%5|%6|%7").arg(minNameLength).arg(maxNameLength).arg(allowLowercase).arg(allowUppercase).arg(allowNumerics).arg(allowPunctuationPrefix).arg(allowedPunctuation);
|
||||
|
||||
if (user.length() < minNameLength || user.length() > maxNameLength)
|
||||
return false;
|
||||
|
||||
bool allowPunctuationPrefix = settingsCache->value("users/allowpunctuationprefix", false).toBool();
|
||||
QString allowedPunctuation = settingsCache->value("users/allowedpunctuation", "_").toString();
|
||||
if (!allowPunctuationPrefix && allowedPunctuation.contains(user.at(0)))
|
||||
return false;
|
||||
|
||||
QString regEx("[");
|
||||
if (settingsCache->value("users/allowlowercase", true).toBool())
|
||||
if (allowLowercase)
|
||||
regEx.append("a-z");
|
||||
if (settingsCache->value("users/allowuppercase", true).toBool())
|
||||
if (allowUppercase)
|
||||
regEx.append("A-Z");
|
||||
if(settingsCache->value("users/allownumerics", true).toBool())
|
||||
if(allowNumerics)
|
||||
regEx.append("0-9");
|
||||
regEx.append(QRegExp::escape(allowedPunctuation));
|
||||
regEx.append("]+");
|
||||
@@ -242,7 +247,8 @@ AuthenticationResult Servatrice_DatabaseInterface::checkUserPassword(Server_Prot
|
||||
if (!checkSql())
|
||||
return UnknownUser;
|
||||
|
||||
if (!usernameIsValid(user))
|
||||
QString error;
|
||||
if (!usernameIsValid(user, error))
|
||||
return UsernameInvalid;
|
||||
|
||||
if (checkUserIsBanned(handler->getAddress(), user, reasonStr, banSecondsLeft))
|
||||
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
void lockSessionTables();
|
||||
void unlockSessionTables();
|
||||
bool userSessionExists(const QString &userName);
|
||||
bool usernameIsValid(const QString &user);
|
||||
bool usernameIsValid(const QString &user, QString & error);
|
||||
bool checkUserIsBanned(const QString &ipAddress, const QString &userName, QString &banReason, int &banSecondsRemaining);
|
||||
|
||||
bool getRequireRegistration();
|
||||
|
||||
@@ -788,8 +788,14 @@ Response::ResponseCode ServerSocketInterface::cmdRegisterAccount(const Command_R
|
||||
}
|
||||
|
||||
// TODO: Move this method outside of the db interface
|
||||
if (!sqlInterface->usernameIsValid(userName))
|
||||
QString errorString;
|
||||
if (!sqlInterface->usernameIsValid(userName, errorString))
|
||||
{
|
||||
Response_Register *re = new Response_Register;
|
||||
re->set_denied_reason_str(errorString.toStdString());
|
||||
rc.setResponseExtension(re);
|
||||
return Response::RespUsernameInvalid;
|
||||
}
|
||||
|
||||
if(sqlInterface->userExists(userName))
|
||||
return Response::RespUserAlreadyExists;
|
||||
|
||||
Reference in New Issue
Block a user