From 0b7f4c134cd26d3de2a0b0bc38ee54092590995c Mon Sep 17 00:00:00 2001 From: Kevin Boxhoorn Date: Mon, 17 Oct 2016 21:24:42 +1100 Subject: [PATCH] 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` --- cockatrice/src/window_main.cpp | 16 +++++++++++++--- servatrice/servatrice.ini.example | 12 ++++++++++++ servatrice/src/servatrice_database_interface.cpp | 15 ++++++++++++++- servatrice/src/settingscache.cpp | 10 +++++++--- servatrice/src/settingscache.h | 3 +++ 5 files changed, 49 insertions(+), 7 deletions(-) diff --git a/cockatrice/src/window_main.cpp b/cockatrice/src/window_main.cpp index 5c1b97b5..4db0895f 100644 --- a/cockatrice/src/window_main.cpp +++ b/cockatrice/src/window_main.cpp @@ -404,9 +404,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:") + "