[users] Refactor validity-checking
- provide a structured datatype for password status
This commit is contained in:
parent
1a7b2668dc
commit
34946ecdee
@ -427,17 +427,23 @@ Config::passwordStatus( const QString& pw1, const QString& pw2 ) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Config::PasswordStatus
|
||||||
|
Config::userPasswordStatus() const
|
||||||
|
{
|
||||||
|
return passwordStatus( m_userPassword, m_userPasswordSecondary );
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
Config::userPasswordValidity() const
|
Config::userPasswordValidity() const
|
||||||
{
|
{
|
||||||
auto p = passwordStatus( m_userPassword, m_userPasswordSecondary );
|
auto p = userPasswordStatus();
|
||||||
return p.first;
|
return p.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
Config::userPasswordStatus() const
|
Config::userPasswordMessage() const
|
||||||
{
|
{
|
||||||
auto p = passwordStatus( m_userPassword, m_userPasswordSecondary );
|
auto p = userPasswordStatus();
|
||||||
return p.second;
|
return p.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -494,27 +500,12 @@ Config::rootPasswordSecondary() const
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
Config::PasswordStatus
|
||||||
Config::rootPasswordValidity() const
|
|
||||||
{
|
|
||||||
if ( writeRootPassword() && !reuseUserPasswordForRoot() )
|
|
||||||
{
|
|
||||||
auto p = passwordStatus( m_rootPassword, m_rootPasswordSecondary );
|
|
||||||
return p.first;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return userPasswordValidity();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString
|
|
||||||
Config::rootPasswordStatus() const
|
Config::rootPasswordStatus() const
|
||||||
{
|
{
|
||||||
if ( writeRootPassword() && !reuseUserPasswordForRoot() )
|
if ( writeRootPassword() && !reuseUserPasswordForRoot() )
|
||||||
{
|
{
|
||||||
auto p = passwordStatus( m_rootPassword, m_rootPasswordSecondary );
|
return passwordStatus( m_rootPassword, m_rootPasswordSecondary );
|
||||||
return p.second;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -522,6 +513,20 @@ Config::rootPasswordStatus() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
Config::rootPasswordValidity() const
|
||||||
|
{
|
||||||
|
auto p = rootPasswordStatus();
|
||||||
|
return p.first;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
Config::rootPasswordMessage() const
|
||||||
|
{
|
||||||
|
auto p = rootPasswordStatus();
|
||||||
|
return p.second;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
STATICTEST void
|
STATICTEST void
|
||||||
setConfigurationDefaultGroups( const QVariantMap& map, QStringList& defaultGroups )
|
setConfigurationDefaultGroups( const QVariantMap& map, QStringList& defaultGroups )
|
||||||
|
@ -63,13 +63,13 @@ class Config : public QObject
|
|||||||
Q_PROPERTY( QString userPasswordSecondary READ userPasswordSecondary WRITE setUserPasswordSecondary NOTIFY
|
Q_PROPERTY( QString userPasswordSecondary READ userPasswordSecondary WRITE setUserPasswordSecondary NOTIFY
|
||||||
userPasswordSecondaryChanged )
|
userPasswordSecondaryChanged )
|
||||||
Q_PROPERTY( int userPasswordValidity READ userPasswordValidity NOTIFY userPasswordStatusChanged STORED false )
|
Q_PROPERTY( int userPasswordValidity READ userPasswordValidity NOTIFY userPasswordStatusChanged STORED false )
|
||||||
Q_PROPERTY( QString userPasswordStatus READ userPasswordStatus NOTIFY userPasswordStatusChanged STORED false )
|
Q_PROPERTY( QString userPasswordMessage READ userPasswordMessage NOTIFY userPasswordStatusChanged STORED false )
|
||||||
|
|
||||||
Q_PROPERTY( QString rootPassword READ rootPassword WRITE setRootPassword NOTIFY rootPasswordChanged )
|
Q_PROPERTY( QString rootPassword READ rootPassword WRITE setRootPassword NOTIFY rootPasswordChanged )
|
||||||
Q_PROPERTY( QString rootPasswordSecondary READ rootPasswordSecondary WRITE setRootPasswordSecondary NOTIFY
|
Q_PROPERTY( QString rootPasswordSecondary READ rootPasswordSecondary WRITE setRootPasswordSecondary NOTIFY
|
||||||
rootPasswordSecondaryChanged )
|
rootPasswordSecondaryChanged )
|
||||||
Q_PROPERTY( int rootPasswordValidity READ rootPasswordValidity NOTIFY rootPasswordStatusChanged STORED false )
|
Q_PROPERTY( int rootPasswordValidity READ rootPasswordValidity NOTIFY rootPasswordStatusChanged STORED false )
|
||||||
Q_PROPERTY( QString rootPasswordStatus READ rootPasswordStatus NOTIFY rootPasswordStatusChanged STORED false )
|
Q_PROPERTY( QString rootPasswordMessage READ rootPasswordMessage NOTIFY rootPasswordStatusChanged STORED false )
|
||||||
|
|
||||||
Q_PROPERTY( bool writeRootPassword READ writeRootPassword CONSTANT )
|
Q_PROPERTY( bool writeRootPassword READ writeRootPassword CONSTANT )
|
||||||
Q_PROPERTY( bool reuseUserPasswordForRoot READ reuseUserPasswordForRoot WRITE setReuseUserPasswordForRoot NOTIFY
|
Q_PROPERTY( bool reuseUserPasswordForRoot READ reuseUserPasswordForRoot WRITE setReuseUserPasswordForRoot NOTIFY
|
||||||
@ -101,6 +101,16 @@ public:
|
|||||||
Invalid = 2
|
Invalid = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** @brief Full password status
|
||||||
|
*
|
||||||
|
* A password's status is in two parts:
|
||||||
|
* - a validity (valid, weak or invalid)
|
||||||
|
* - a message describing that validity
|
||||||
|
* The message is empty when the password is valid, but
|
||||||
|
* weak and invalid passwords have an explanatory message.
|
||||||
|
*/
|
||||||
|
using PasswordStatus = QPair< PasswordValidity, QString >;
|
||||||
|
|
||||||
Config( QObject* parent = nullptr );
|
Config( QObject* parent = nullptr );
|
||||||
~Config();
|
~Config();
|
||||||
|
|
||||||
@ -149,7 +159,8 @@ public:
|
|||||||
QString userPassword() const { return m_userPassword; }
|
QString userPassword() const { return m_userPassword; }
|
||||||
QString userPasswordSecondary() const { return m_userPasswordSecondary; }
|
QString userPasswordSecondary() const { return m_userPasswordSecondary; }
|
||||||
int userPasswordValidity() const;
|
int userPasswordValidity() const;
|
||||||
QString userPasswordStatus() const;
|
QString userPasswordMessage() const;
|
||||||
|
PasswordStatus userPasswordStatus() const;
|
||||||
|
|
||||||
// The root password **may** be entered in the UI, or may be suppressed
|
// The root password **may** be entered in the UI, or may be suppressed
|
||||||
// entirely when writeRootPassword is off, or may be equal to
|
// entirely when writeRootPassword is off, or may be equal to
|
||||||
@ -157,7 +168,8 @@ public:
|
|||||||
QString rootPassword() const;
|
QString rootPassword() const;
|
||||||
QString rootPasswordSecondary() const;
|
QString rootPasswordSecondary() const;
|
||||||
int rootPasswordValidity() const;
|
int rootPasswordValidity() const;
|
||||||
QString rootPasswordStatus() const;
|
QString rootPasswordMessage() const;
|
||||||
|
PasswordStatus rootPasswordStatus() const;
|
||||||
|
|
||||||
static const QStringList& forbiddenLoginNames();
|
static const QStringList& forbiddenLoginNames();
|
||||||
static const QStringList& forbiddenHostNames();
|
static const QStringList& forbiddenHostNames();
|
||||||
@ -220,7 +232,7 @@ signals:
|
|||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPair< PasswordValidity, QString > passwordStatus( const QString&, const QString& ) const;
|
PasswordStatus passwordStatus( const QString&, const QString& ) const;
|
||||||
|
|
||||||
QStringList m_defaultGroups;
|
QStringList m_defaultGroups;
|
||||||
QString m_userShell;
|
QString m_userShell;
|
||||||
|
Loading…
Reference in New Issue
Block a user