[users] Refactor validity-checking

- provide a structured datatype for password status
main
Adriaan de Groot 4 years ago
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
Config::userPasswordValidity() const
{
auto p = passwordStatus( m_userPassword, m_userPasswordSecondary );
auto p = userPasswordStatus();
return p.first;
}
QString
Config::userPasswordStatus() const
Config::userPasswordMessage() const
{
auto p = passwordStatus( m_userPassword, m_userPasswordSecondary );
auto p = userPasswordStatus();
return p.second;
}
@ -494,32 +500,31 @@ Config::rootPasswordSecondary() const
return QString();
}
int
Config::rootPasswordValidity() const
Config::PasswordStatus
Config::rootPasswordStatus() const
{
if ( writeRootPassword() && !reuseUserPasswordForRoot() )
{
auto p = passwordStatus( m_rootPassword, m_rootPasswordSecondary );
return p.first;
return passwordStatus( m_rootPassword, m_rootPasswordSecondary );
}
else
{
return userPasswordValidity();
return userPasswordStatus();
}
}
int
Config::rootPasswordValidity() const
{
auto p = rootPasswordStatus();
return p.first;
}
QString
Config::rootPasswordStatus() const
Config::rootPasswordMessage() const
{
if ( writeRootPassword() && !reuseUserPasswordForRoot() )
{
auto p = passwordStatus( m_rootPassword, m_rootPasswordSecondary );
return p.second;
}
else
{
return userPasswordStatus();
}
auto p = rootPasswordStatus();
return p.second;
}

@ -63,13 +63,13 @@ class Config : public QObject
Q_PROPERTY( QString userPasswordSecondary READ userPasswordSecondary WRITE setUserPasswordSecondary NOTIFY
userPasswordSecondaryChanged )
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 rootPasswordSecondary READ rootPasswordSecondary WRITE setRootPasswordSecondary NOTIFY
rootPasswordSecondaryChanged )
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 reuseUserPasswordForRoot READ reuseUserPasswordForRoot WRITE setReuseUserPasswordForRoot NOTIFY
@ -101,6 +101,16 @@ public:
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();
@ -149,7 +159,8 @@ public:
QString userPassword() const { return m_userPassword; }
QString userPasswordSecondary() const { return m_userPasswordSecondary; }
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
// entirely when writeRootPassword is off, or may be equal to
@ -157,7 +168,8 @@ public:
QString rootPassword() const;
QString rootPasswordSecondary() const;
int rootPasswordValidity() const;
QString rootPasswordStatus() const;
QString rootPasswordMessage() const;
PasswordStatus rootPasswordStatus() const;
static const QStringList& forbiddenLoginNames();
static const QStringList& forbiddenHostNames();
@ -220,7 +232,7 @@ signals:
private:
QPair< PasswordValidity, QString > passwordStatus( const QString&, const QString& ) const;
PasswordStatus passwordStatus( const QString&, const QString& ) const;
QStringList m_defaultGroups;
QString m_userShell;

Loading…
Cancel
Save