From d0db56e964b491c28c2aeadbbd217c626c525927 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 9 May 2022 14:58:46 +0200 Subject: [PATCH] [users] Simplify code: use contains() instead of a for-loop --- src/modules/users/Config.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/modules/users/Config.cpp b/src/modules/users/Config.cpp index a9287205f..78782aef0 100644 --- a/src/modules/users/Config.cpp +++ b/src/modules/users/Config.cpp @@ -219,13 +219,6 @@ Config::loginNameStatus() const { return tr( "Your username is too long." ); } - for ( const QString& badName : forbiddenLoginNames() ) - { - if ( 0 == QString::compare( badName, m_loginName, Qt::CaseSensitive ) ) - { - return tr( "'%1' is not allowed as username." ).arg( badName ); - } - } QRegExp validateFirstLetter( "^[a-z_]" ); if ( validateFirstLetter.indexIn( m_loginName ) != 0 ) @@ -237,6 +230,12 @@ Config::loginNameStatus() const return tr( "Only lowercase letters, numbers, underscore and hyphen are allowed." ); } + // Although we've made the list lower-case, and the RE above forces lower-case, still pass the flag + if ( forbiddenLoginNames().contains( m_loginName, Qt::CaseInsensitive ) ) + { + return tr( "'%1' is not allowed as username." ).arg( m_loginName ); + } + return QString(); } @@ -289,12 +288,11 @@ Config::hostnameStatus() const { return tr( "Your hostname is too long." ); } - for ( const QString& badName : forbiddenHostNames() ) + + // "LocalHost" is just as forbidden as "localhost" + if ( forbiddenHostNames().contains( m_hostname, Qt::CaseInsensitive ) ) { - if ( 0 == QString::compare( badName, m_hostname, Qt::CaseSensitive ) ) - { - return tr( "'%1' is not allowed as hostname." ).arg( badName ); - } + return tr( "'%1' is not allowed as hostname." ).arg( m_hostname ); } if ( !HOSTNAME_RX.exactMatch( m_hostname ) )