[users] Simplify code: use contains() instead of a for-loop

This commit is contained in:
Adriaan de Groot 2022-05-09 14:58:46 +02:00
parent ef9bf2650c
commit d0db56e964

View File

@ -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 ) )