Index: sources/view/settings/VSettings.cpp =================================================================== diff -u -ra5760947d3ed0d2748ba023a1c25e3c6aa0b1de1 -r88a09dc4b26cfdd5fd111d20adfb9cb60697186c --- sources/view/settings/VSettings.cpp (.../VSettings.cpp) (revision a5760947d3ed0d2748ba023a1c25e3c6aa0b1de1) +++ sources/view/settings/VSettings.cpp (.../VSettings.cpp) (revision 88a09dc4b26cfdd5fd111d20adfb9cb60697186c) @@ -225,47 +225,69 @@ } /*! - * \brief VSettings::isPasswordValid - * \details Validates the passed string for conforming to the - * - at least one capital letter, - * - at least one digit, - * - at least one symbol - * rule - * \param vPassword - the string to check - * \returns true if string pass conforms, false otherwise + * \brief Return whether the password has the minimum character limit + * \param[in] password password to check + * \return true if the password contains requirement */ -bool View::VSettings::isPasswordValid(const QString &vPassword) { - int minLen = 10 ; // in the SRS the max is required to be 12 which seems incorrect and I didn't set it here. - QString pla = "(?=.*[%1])" ; // positive look ahead - QString regSntnc = "^%1$" ; // regular expression sentence with has a start/end - QString regUpper = "A-Z" ; - QString regLower = "a-z" ; - QString regDigit = "0-9" ; - QString regSymbl = "!\"#$%&'()*+,\\-./:;<=>?@[\\\\\\]^_`{\\|}~"; - QString rln = "[%1]{%2,}" ; +bool View::VSettings::passwordContainsCharacterLimit(const QString &vPassword) const +{ + return vPassword.size() >= 10; +} - // "^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{\|}~])[A-Za-z0-9!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{\|}~]{10,}$" - // !"#$%&'()*+,\\-./:;<=>?@[\\\\\\]^_`{\\|}~ - QString regStr = regSntnc.arg( - pla.arg(regUpper) + - pla.arg(regLower) + - pla.arg(regDigit) + - pla.arg(regSymbl) + - rln.arg(regUpper + - regLower + - regDigit + - regSymbl) - .arg(minLen ) - ); - QRegularExpression passwordRegex(regStr); - bool ok; +/*! + * \brief Return whether the password has a upper case letter + * \param[in] password password to check + * \return true if the password contains requirement + */ +bool View::VSettings::passwordContainsUpperCase(const QString &vPassword) const +{ + static const QRegularExpression upperCaseLetter("[A-Z]"); + return vPassword.contains(upperCaseLetter); +} - //DEBUG: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ - //DEBUG: vPassword = "Ab0!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" - ok = passwordRegex.match(vPassword).hasMatch(); - return ok; +/*! + * \brief Return whether the password has a lower case letter + * \param[in] password password to check + * \return true if the password contains requirement + */ +bool View::VSettings::passwordContainsLowerCase(const QString &vPassword) const +{ + static const QRegularExpression lowerCaseLetter("[a-z]"); + return vPassword.contains(lowerCaseLetter); } +/*! + * \brief Return whether the password has a digit + * \param[in] password password to check + * \return true if the password contains requirement + */ +bool View::VSettings::passwordContainsDigit(const QString &vPassword) const +{ + static const QRegularExpression number("[0-9]"); + return vPassword.contains(number); +} + +bool View::VSettings::passwordContainsSymbol(const QString &vPassword) const +{ + static const QRegularExpression symbol( + QStringLiteral("[%1]").arg(QRegularExpression::escape("{}[],.<>;:'\"?/|\\`~!@#$%^&*()_-+="))); + return vPassword.contains(symbol); +} + +/*! + * \brief Return whether the password is high strength. + * \param[in] password password to check + * \return true if the password is high strength and false otherwise. + */ +bool View::VSettings::isPasswordHighStrength(const QString &vPassword) const +{ + return passwordContainsUpperCase(vPassword) && + passwordContainsLowerCase(vPassword) && + passwordContainsDigit(vPassword) && + passwordContainsSymbol(vPassword) && + passwordContainsCharacterLimit(vPassword); +} + QString View::VSettings::hashedPassword(const QString &vPassword, bool vIsService) { bool ok;