Index: sources/view/settings/VSettings.cpp =================================================================== diff -u -ra5760947d3ed0d2748ba023a1c25e3c6aa0b1de1 -redb8ee3edc41b1d324cd8a53e8e27a2a58289563 --- sources/view/settings/VSettings.cpp (.../VSettings.cpp) (revision a5760947d3ed0d2748ba023a1c25e3c6aa0b1de1) +++ sources/view/settings/VSettings.cpp (.../VSettings.cpp) (revision edb8ee3edc41b1d324cd8a53e8e27a2a58289563) @@ -40,6 +40,7 @@ PROPERTY_POST_CONNECTION(VSettings, servicePass ); PROPERTY_POST_CONNECTION(VSettings, alarmVolume ); PROPERTY_POST_CONNECTION(VSettings, roWaterMode ); + PROPERTY_POST_CONNECTION(VSettings, userMode ); init = true; } @@ -60,6 +61,14 @@ } } +void VSettings::userMode_post(const bool &vuserMode_post) { + //TODO The Settings shall be the Singleton SettingsController and modify the MSettings like the others. + if ( Storage::Settings::save(userModeGroup(), userModeKey(), QString::number(vuserMode_post)) != 0 ) { + userMode(false); + // FIXME: Notify UI with a message + } +} + void VSettings::alarmVolume_post(const quint8 &valarmVolume) { //TODO The Settings shall be the Singleton SettingsController and modify the MSettings like the others. Storage::Settings::save(alarmVolumeGroup(), alarmVolumeKey(), QString::number(valarmVolume)); @@ -96,6 +105,12 @@ keyValue[key] = mRoWaterMode ; roWaterMode ( mRoWaterMode); } + else if ( isuserMode (category, group, key) ) { + bool mUserMode; + mUserMode = _Settings.value(category, group, key).toBool (); + keyValue[key] = mUserMode ; + userMode ( mUserMode); + } else if ( isalarmVolume (category, group, key) ) { quint8 mAlarmVolume; mAlarmVolume = _Settings.value(category, group, key).toInt (); // returns 0 if fails, so no error checking needed. @@ -118,6 +133,7 @@ servicePass ( _servicePass ); alarmVolume ( _alarmVolume ); roWaterMode ( _roWaterMode ); + userMode ( _userMode ); //DEBUG qDebug() << servicePass() << roWaterMode() << alarmVolume(); adjustment(true); @@ -225,47 +241,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;