cutelyst 4.3.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
|
Validates an input field with libpwquality to check password quality. More...
#include <Cutelyst/Plugins/Utils/validatorpwquality.h>
Public Member Functions | |
ValidatorPwQuality (const QString &field, int threshold=ValidatorPwQuality::defaultThreshold, const QVariant &options=QVariant(), const QString &userName=QString(), const QString &oldPassword=QString(), const ValidatorMessages &messages=ValidatorMessages()) | |
~ValidatorPwQuality () override | |
Public Member Functions inherited from Cutelyst::ValidatorRule | |
ValidatorRule (const QString &field, const ValidatorMessages &messages={}, const QString &defValKey={}, QByteArrayView validatorName=nullptr) | |
virtual | ~ValidatorRule () |
Deconstructs the ValidatorRule. | |
Static Public Member Functions | |
static QString | errorString (Context *c, int returnValue, const QString &label=QString(), int threshold=0) |
static int | validate (const QString &value, const QVariant &options=QVariant(), const QString &oldPassword=QString(), const QString &user=QString()) |
Returns the password quality score for value. | |
Static Public Attributes | |
static constexpr int | defaultThreshold |
Protected Member Functions | |
QString | genericValidationError (Context *c, const QVariant &errorData) const override |
ValidatorReturnType | validate (Context *c, const ParamsMultiMap ¶ms) const override |
Protected Member Functions inherited from Cutelyst::ValidatorRule | |
ValidatorRule (ValidatorRulePrivate &dd) | |
QString | debugString (Context *c) const |
void | defaultValue (Context *c, ValidatorReturnType *result) const |
QString | field () const noexcept |
virtual QString | genericParsingError (Context *c, const QVariant &errorData={}) const |
virtual QString | genericValidationDataError (Context *c, const QVariant &errorData={}) const |
QString | label (Context *c) const |
QString | parsingError (Context *c, const QVariant &errorData={}) const |
bool | trimBefore () const noexcept |
QString | validationDataError (Context *c, const QVariant &errorData={}) const |
QString | validationError (Context *c, const QVariant &errorData={}) const |
QString | value (const ParamsMultiMap ¶ms) const |
This validator uses libpwquality to generate a password quality score that is compared against a threshold. If it is below the threshold, the validation fails. According to libpwquality a score of 0-30 is of low, a score of 30-60 of medium and a score of 60-100 of high quality. Everything below 0 is an error and the password should not be used.
As this validator relies on an external library, it will not be included and build by default. Use either -DPLUGIN_VALIDATOR_PWQUALITY:BOOL=ON
or -DBUILD_ALL:BOOL=ON
when configuring Cutelyst for build with cmake. In your Cutelyst application you can check if CUTELYST_VALIDATOR_WITH_PWQUALITY
has been defined to see if this validator is available.
ValidatorPwQuality can take additional options. To learn more about the available options see man 5 pwquality.conf
. The options value can be either a QVariantMap containing the options or a QString specifying a file name that will be read by libpwquality. For the constructor the options will also be searched in the current stash if it is a QString. The stash value should than be either a QVariantMap or a QString pointing to a configuration file. All values in the QVariantMap used to specify options, have to be convertible into QString. The QVariantMap does not have to contain all available option keys. For keys that are not contained, the default values of libpwquality will be used. If the options QVariant is not valid or if a contained QString or QVariantMap is empty, the options from the default libpwquality configuration file will be read.
Definition at line 59 of file validatorpwquality.h.
|
explicit |
Constructs a new ValidatorPwQuality object with the given parameters.
field | Name of the input field to validate. |
threshold | The quality score threshold below the validation fails. |
options | <a hrefd=#options">Options for libpwquality. Use invalid QVariant to omit. |
userName | Input params key or stash key containing the user name, used for quality checks. Will first try params, than stash. Leave empty to omit. |
oldPassword | Input params key or stash key containing the old password, used for quality checks. Will first try params, than stash. Leave empty to omit. |
messages | Custom error messages if validation fails. |
Definition at line 14 of file validatorpwquality.cpp.
|
overridedefault |
Destroys the ValidatorPwQuality object.
|
static |
Returns a human readable string for the return value of ValidatorPwQuality::validate().
c | Current context, used for translations. |
returnValue | The return value of ValidatorPwQuality::validate() |
label | Optional label used in the returned string. |
threshold | The threshold below that a password is invalid. |
Definition at line 121 of file validatorpwquality.cpp.
References QString::arg(), QString::isEmpty(), Cutelyst::ValidatorRule::label(), QString::number(), and Cutelyst::Context::qtTrId().
Referenced by genericValidationError().
|
overrideprotectedvirtual |
Returns a generic error message if validation failed.
Reimplemented from Cutelyst::ValidatorRule.
Definition at line 409 of file validatorpwquality.cpp.
References errorString(), Cutelyst::ValidatorRule::label(), and QVariant::toInt().
|
overrideprotectedvirtual |
Performs the validation on the input params and returns the result.
If validation succeeded, ValidatorReturnType::value will contain the input paramter value as QString.
Implements Cutelyst::ValidatorRule.
Definition at line 350 of file validatorpwquality.cpp.
References QList::data(), Cutelyst::ValidatorRule::debugString(), Cutelyst::ValidatorReturnType::errorMessage, QString::isEmpty(), QMetaType::QString, QMetaType::QVariantMap, QList::size(), Cutelyst::Context::stash(), validate(), Cutelyst::ValidatorRule::validationError(), Cutelyst::ValidatorReturnType::value, QMultiMap::value(), and Cutelyst::ValidatorRule::value().
|
staticconstexpr |
The default quality score threshold below the validation fails.
Definition at line 65 of file validatorpwquality.h.