Cutelyst
2.13.0
|
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=30, const QVariant &options=QVariant(), const QString &userName=QString(), const QString &oldPassword=QString(), const ValidatorMessages &messages=ValidatorMessages()) | |
Constructs a new ValidatorPwQuality with the given parameters. More... | |
~ValidatorPwQuality () override | |
Deconstructs the ValidatorPwQuality. | |
![]() | |
ValidatorRule (const QString &field, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString()) | |
Constructs a new ValidatorRule with the given parameters. More... | |
virtual | ~ValidatorRule () |
Deconstructs the ValidatorRule. | |
Static Public Member Functions | |
static QString | errorString (Context *c, int returnValue, const QString &label=QString(), int threshold=0) |
Returns a human readable string for the return value of ValidatorPwQuality::validate() More... | |
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. More... | |
Protected Member Functions | |
QString | genericValidationError (Context *c, const QVariant &errorData) const override |
Returns a generic error message if validation failed. More... | |
ValidatorReturnType | validate (Context *c, const ParamsMultiMap ¶ms) const override |
Performs the validation and returns the result. More... | |
![]() | |
ValidatorRule (ValidatorRulePrivate &dd) | |
Constructs a new ValidatorRule object with the given private class. More... | |
void | defaultValue (Context *c, ValidatorReturnType *result, const char *validatorName) const |
I a defValKey has been set in the constructor, this will try to get the default value from the stash and put it into the result. More... | |
QString | field () const |
Returns the name of the field to validate. More... | |
virtual QString | genericParsingError (Context *c, const QVariant &errorData=QVariant()) const |
Returns a generic error message if an error occures while parsing input. More... | |
virtual QString | genericValidationDataError (Context *c, const QVariant &errorData=QVariant()) const |
Returns a generic error message if any validation data is missing or invalid. More... | |
QString | label (Context *c) const |
Returns the human readable field label used for generic error messages. More... | |
QString | parsingError (Context *c, const QVariant &errorData=QVariant()) const |
Returns an error message if an error occured while parsing input. More... | |
bool | trimBefore () const |
Returns true if the field value should be trimmed before validation. More... | |
QString | validationDataError (Context *c, const QVariant &errorData=QVariant()) const |
Returns an error message if any validation data is missing or invalid. More... | |
QString | validationError (Context *c, const QVariant &errorData=QVariant()) const |
Returns a descriptive error message if validation failed. More... | |
QString | value (const ParamsMultiMap ¶ms) const |
Returns the value of the field from the input params. | |
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 64 of file validatorpwquality.h.
|
explicit |
field | Name of the input field to validate. |
threshold | The quality score threshold below the validation fails. |
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 25 of file validatorpwquality.cpp.
|
static |
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 114 of file validatorpwquality.cpp.
References Cutelyst::ValidatorRule::label(), and Cutelyst::Context::translate().
Referenced by genericValidationError().
|
overrideprotectedvirtual |
The errorData will contain the score returned by ValidatorPqQuality::validate()
Reimplemented from Cutelyst::ValidatorRule.
Definition at line 374 of file validatorpwquality.cpp.
References errorString(), and Cutelyst::ValidatorRule::label().
|
overrideprotectedvirtual |
If validation succeeded, ValidatorReturnType::value will contain the input paramter value as QString.
Implements Cutelyst::ValidatorRule.
Definition at line 319 of file validatorpwquality.cpp.
References Cutelyst::ValidatorReturnType::errorMessage, Cutelyst::ValidatorRule::field(), Cutelyst::Context::stash(), validate(), Cutelyst::ValidatorRule::validationError(), Cutelyst::ValidatorReturnType::value, and Cutelyst::ValidatorRule::value().