diff --git a/cockatrice/src/window_main.cpp b/cockatrice/src/window_main.cpp
index 2b0b4c4d..7e434361 100644
--- a/cockatrice/src/window_main.cpp
+++ b/cockatrice/src/window_main.cpp
@@ -408,9 +408,9 @@ QString MainWindow::extractInvalidUsernameMessage(QString & in)
{
QString out = tr("Invalid username.") + "
";
QStringList rules = in.split(QChar('|'));
- if (rules.size() == 7)
+ if (rules.size() == 7 || rules.size() == 9)
{
- out += tr("Your username must respect these rules:") + "
";
+ out += tr("Your username must respect these rules:") + "";
out += "- " + tr("is %1 - %2 characters long").arg(rules.at(0)).arg(rules.at(1)) + "
";
out += "- " + tr("can %1 contain lowercase characters").arg((rules.at(2).toInt() > 0) ? "" : tr("NOT")) + "
";
@@ -421,6 +421,16 @@ QString MainWindow::extractInvalidUsernameMessage(QString & in)
out += "- " + tr("can contain the following punctuation: %1").arg(rules.at(6).toHtmlEscaped()) + "
";
out += "- " + tr("first character can %1 be a punctuation mark").arg((rules.at(5).toInt() > 0) ? "" : tr("NOT")) + "
";
+
+ if (rules.size() == 9)
+ {
+ if (rules.at(7).size() > 0)
+ out += "- " + tr("can not contain any of the following words: %1").arg(rules.at(7).toHtmlEscaped()) + "
";
+
+ if (rules.at(8).size() > 0)
+ out += "- " + tr("can not match any of the following expressions: %1").arg(rules.at(8).toHtmlEscaped()) + "
";
+ }
+
out += "
";
}
else
@@ -531,7 +541,7 @@ void MainWindow::retranslateUi()
dbMenu->setTitle(tr("C&ard Database"));
aOpenCustomFolder->setText(tr("Open custom image folder"));
aOpenCustomsetsFolder->setText(tr("Open custom sets folder"));
- aAddCustomSet->setText(tr("Add custom sets/cards"));
+ aAddCustomSet->setText(tr("Add custom sets/cards"));
aEditSets->setText(tr("&Edit sets..."));
aEditTokens->setText(tr("Edit &tokens..."));
diff --git a/servatrice/servatrice.ini.example b/servatrice/servatrice.ini.example
index 466810d7..42013783 100644
--- a/servatrice/servatrice.ini.example
+++ b/servatrice/servatrice.ini.example
@@ -107,6 +107,18 @@ allowedpunctuation=_.-
; If a username can begin with punctuation defined in allowedpunctuation
allowpunctuationprefix=false
+; Disallow usernames containing these words. This list is comma seperated, e.g.
+; "admin,user,name"
+disallowedwords="admin"
+
+; Disallow usernames matching these regular expressions. This list is comma
+; separated, e.g. "\\w+\\d+,\\d{2}user", hence you cannot use commas in your
+; expressions. Backslashes must be escaped, so `\w+\d+` becomes `\\w+\\d+`.
+; WARNING: Complex expressions can be harmful to performance. Please make sure
+; your expressions are considered well formed. See this page for info:
+; http://www.regular-expressions.info/catastrophic.html
+disallowedregexp=""
+
[registration]
; Servatrice can process registration requests to add new users on the fly.
diff --git a/servatrice/src/servatrice_database_interface.cpp b/servatrice/src/servatrice_database_interface.cpp
index 25aa4b6a..d29fddad 100644
--- a/servatrice/src/servatrice_database_interface.cpp
+++ b/servatrice/src/servatrice_database_interface.cpp
@@ -132,7 +132,12 @@ bool Servatrice_DatabaseInterface::usernameIsValid(const QString &user, QString
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);
+ QString disallowedWordsStr = settingsCache->value("users/disallowedwords", "").toString();
+ QStringList disallowedWords = disallowedWordsStr.split(",", QString::SkipEmptyParts);
+ disallowedWords.removeDuplicates();
+ QString disallowedRegExpStr = settingsCache->value("users/disallowedregexp", "").toString();
+
+ error = QString("%1|%2|%3|%4|%5|%6|%7|%8|%9").arg(minNameLength).arg(maxNameLength).arg(allowLowercase).arg(allowUppercase).arg(allowNumerics).arg(allowPunctuationPrefix).arg(allowedPunctuation).arg(disallowedWordsStr).arg(disallowedRegExpStr);
if (user.length() < minNameLength || user.length() > maxNameLength)
return false;
@@ -140,6 +145,14 @@ bool Servatrice_DatabaseInterface::usernameIsValid(const QString &user, QString
if (!allowPunctuationPrefix && allowedPunctuation.contains(user.at(0)))
return false;
+ for (const QString &word : disallowedWords) {
+ if (user.contains(word, Qt::CaseInsensitive)) return false;
+ }
+
+ for (const QRegExp ®Exp : settingsCache->disallowedRegExp) {
+ if (regExp.exactMatch(user)) return false;
+ }
+
QString regEx("[");
if (allowLowercase)
regEx.append("a-z");
diff --git a/servatrice/src/settingscache.cpp b/servatrice/src/settingscache.cpp
index 5569d5af..5009365b 100644
--- a/servatrice/src/settingscache.cpp
+++ b/servatrice/src/settingscache.cpp
@@ -4,14 +4,18 @@
#include
SettingsCache::SettingsCache(const QString & fileName, QSettings::Format format, QObject * parent)
-:QSettings(fileName, format, parent)
+ :QSettings(fileName, format, parent)
{
-
+ QStringList disallowedRegExpStr = value("users/disallowedregexp", "").toString().split(",", QString::SkipEmptyParts);
+ disallowedRegExpStr.removeDuplicates();
+ for (const QString ®ExpStr : disallowedRegExpStr) {
+ disallowedRegExp.append(QRegExp(regExpStr));
+ }
}
QString SettingsCache::guessConfigurationPath(QString & specificPath)
{
- const QString fileName="servatrice.ini";
+ const QString fileName="servatrice.ini";
#ifdef PORTABLE_BUILD
return fileName;
#endif
diff --git a/servatrice/src/settingscache.h b/servatrice/src/settingscache.h
index 7284d273..75e0a86f 100644
--- a/servatrice/src/settingscache.h
+++ b/servatrice/src/settingscache.h
@@ -3,6 +3,8 @@
#include
#include
+#include
+#include
class SettingsCache : public QSettings {
Q_OBJECT
@@ -11,6 +13,7 @@ private:
public:
SettingsCache(const QString & fileName="servatrice.ini", QSettings::Format format=QSettings::IniFormat, QObject * parent = 0);
static QString guessConfigurationPath(QString & specificPath);
+ QList disallowedRegExp;
};
extern SettingsCache *settingsCache;