Disallow usernames that contain certain words and RegExp (#2200)

* Add `disallowedwords` setting and perform check

Check if any of the words in `disallowedwords` are contained in the username. If
so, return false like other checks.

NOTE: Needs testing for advanced bugs.

* Remove "administrator" from `disallowedwords`

"administrator" contains "admin" anyway, so it is not needed.

* Add error message if username contains a disallowed word

* Add `disallowedregexp` setting and perform check

Check if each expression in `disallowedregexp` exactly matches the username. If
so, return false.

TODO: Add specific error to dialog in `window_main.cpp`.

* Add error message for username matching RegExp

* Fix indentation

* Compile `disallowedregexp` into a QList upon initialization

Reduces system load with each registration request.

* Clean up `isUsernameValid` function

* Fix indentation

* Add backwards compatibility to client

Client can accept either 7 or 9 rules to maintain compatibility with older
versions of server.

* Add examples and warnings to `servatrice.ini`
This commit is contained in:
Kevin Boxhoorn 2016-10-17 21:24:42 +11:00 committed by ctrlaltca
parent f20e2ce2bd
commit 0b7f4c134c
5 changed files with 49 additions and 7 deletions

View file

@ -404,9 +404,9 @@ QString MainWindow::extractInvalidUsernameMessage(QString & in)
{
QString out = tr("Invalid username.") + "<br/>";
QStringList rules = in.split(QChar('|'));
if (rules.size() == 7)
if (rules.size() == 7 || rules.size() == 9)
{
out += tr("Your username must respect these rules:") + "<br><ul>";
out += tr("Your username must respect these rules:") + "<ul>";
out += "<li>" + tr("is %1 - %2 characters long").arg(rules.at(0)).arg(rules.at(1)) + "</li>";
out += "<li>" + tr("can %1 contain lowercase characters").arg((rules.at(2).toInt() > 0) ? "" : tr("NOT")) + "</li>";
@ -417,6 +417,16 @@ QString MainWindow::extractInvalidUsernameMessage(QString & in)
out += "<li>" + tr("can contain the following punctuation: %1").arg(rules.at(6).toHtmlEscaped()) + "</li>";
out += "<li>" + tr("first character can %1 be a punctuation mark").arg((rules.at(5).toInt() > 0) ? "" : tr("NOT")) + "</li>";
if (rules.size() == 9)
{
if (rules.at(7).size() > 0)
out += "<li>" + tr("can not contain any of the following words: %1").arg(rules.at(7).toHtmlEscaped()) + "</li>";
if (rules.at(8).size() > 0)
out += "<li>" + tr("can not match any of the following expressions: %1").arg(rules.at(8).toHtmlEscaped()) + "</li>";
}
out += "</ul>";
}
else
@ -527,7 +537,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..."));