Index: sources/view/settings/VSettings.cpp =================================================================== diff -u -rae153bdecd8bcf0f44b1265791aa96dab1dffe9b -r5c4fe87834faa59fcb7982e783c8ae3390ec2205 --- sources/view/settings/VSettings.cpp (.../VSettings.cpp) (revision ae153bdecd8bcf0f44b1265791aa96dab1dffe9b) +++ sources/view/settings/VSettings.cpp (.../VSettings.cpp) (revision 5c4fe87834faa59fcb7982e783c8ae3390ec2205) @@ -7,7 +7,7 @@ * * \file VSettings.cpp * \author (last) Behrouz NematiPour - * \date (last) 02-Apr-2023 + * \date (last) 18-Jul-2023 * \author (original) Behrouz NematiPour * \date (original) 29-Mar-2021 * @@ -22,22 +22,31 @@ #include "GuiController.h" #include "MSettings.h" #include "Settings.h" +#include VIEW_DEF_CLASS(VSettings) void VSettings::initConnections() { ACTION_VIEW_CONNECTION (SettingsData ); + connect(&_GuiController, SIGNAL(didActionReceive (GuiActionType, const QVariantList &)), + this , SLOT( onActionReceive (GuiActionType, const QVariantList &))); + +} + +void VSettings::initConnectionsSettings() +{ + static bool init = false; if ( init ) return; + PROPERTY_POST_CONNECTION(VSettings, servicePass ); PROPERTY_POST_CONNECTION(VSettings, alarmVolume ); PROPERTY_POST_CONNECTION(VSettings, roWaterMode ); PROPERTY_POST_CONNECTION(VSettings, noCANBus ); - connect(&_GuiController, SIGNAL(didActionReceive (GuiActionType, const QVariantList &)), - this , SLOT( onActionReceive (GuiActionType, const QVariantList &))); - + init = true; } void VSettings::servicePass_post(const QString &vservicePass) { + //TODO The Settings shall be the Singleton SettingsController and modify the MSettings like the others. Storage::Settings settings; if ( settings.save(servicePassCategory(), servicePassGroup(), servicePassKey(), vservicePass) != 0 ) { servicePass(""); @@ -46,6 +55,7 @@ } void VSettings::roWaterMode_post(const bool &vroWaterMode_post) { + //TODO The Settings shall be the Singleton SettingsController and modify the MSettings like the others. Storage::Settings settings; if ( settings.save(roWaterModeCategory(), roWaterModeGroup(), roWaterModeKey(), QString::number(vroWaterMode_post)) != 0 ) { roWaterMode(false); @@ -54,11 +64,13 @@ } void VSettings::alarmVolume_post(const quint8 &valarmVolume) { + //TODO The Settings shall be the Singleton SettingsController and modify the MSettings like the others. Storage::Settings settings; settings.save(alarmVolumeCategory(), alarmVolumeGroup(), alarmVolumeKey(), QString::number(valarmVolume)); } void VSettings::noCANBus_post(const bool &vnoCANBus) { + //TODO The Settings shall be the Singleton SettingsController and modify the MSettings like the others. Storage::Settings settings; settings.save(noCANBusCategory(), noCANBusGroup(), noCANBusKey(), QString::number(vnoCANBus)); } @@ -126,7 +138,10 @@ roWaterMode ( _roWaterMode ); // noCANBus ( _noCANBus ); // This line has been put here to remind developers that it is intentionally removed, to not to add a default value. + //DEBUG qDebug() << servicePass() << roWaterMode() << alarmVolume() << noCANBus(); adjustment(true); + + initConnectionsSettings(); } VSettings::TKeysList VSettings::updateReplacements(const QString &vGroup, const QStringList &vKeys) @@ -266,36 +281,50 @@ return ok; } -#include - -QString VSettings::encryptString(const QString &vString) { - // FIXME: Move this to the utility, storage or settings controller class for more general use. - QString salt = "DVT-HD0004"; // FIXME: Use the actual HD serial number - int iter = 1000; - int len = 16; - auto shuffle = [](const QString &vString) { - // FIXME: Implement this, and make this a function and move this to the utility or storage class for more general use. - QString shuffled = vString; - return shuffled.toUtf8().toHex(); - }; - QCryptographicHash::Algorithm algorithm = QCryptographicHash::Sha512; - QByteArray hashed = QPasswordDigestor::deriveKeyPbkdf2(algorithm, vString.toUtf8(), shuffle(salt), iter, len); - return hashed.toHex(); +QString View::VSettings::hashedPassword(const QString &vPassword, bool vIsService) +{ + bool ok; + QString hashed = encryption::hashedString(vPassword, ok, ! vIsService); + encryptionPass(ok); + return ok ? hashed : ""; } -bool View::VSettings::isPasswordMatch(const QString &vPassword) { - bool valid_password = _servicePass == encryptString(vPassword); - - if (valid_password){ - LOG_DEBUG("Password matched!"); +/*! + * \brief View::VSettings::isServicePasswordMatch + * \details matches the given password string, vPassword, with the service password. + * \param vPassword - the given password string + * \return true if it matches. + */ +bool View::VSettings::isServicePasswordMatch(const QString &vPassword) +{ + //DEBUG qDebug() << __FUNCTION__ << _servicePass << hashedPassword(vPassword, true); + bool isNotEmpty = ( ! vPassword.trimmed().isEmpty() ); + bool isMatch = ( _servicePass == hashedPassword(vPassword, true) ); + bool isValid = isMatch && isNotEmpty; + if ( isValid ) { + LOG_DEBUG("Valid Service Password Entered!"); } - else{ - LOG_DEBUG("Password did not match!"); + else { + LOG_DEBUG("Inalid Service Password Entered!"); } - return valid_password; + return isValid; } -void View::VSettings::updatePassword(const QString &vPassword) +/*! + * \brief View::VSettings::updateServicePassword + * \details Updatest the service password with the given password. + * \param vPassword - the password to be saved as the service password. + */ +void View::VSettings::updateServicePassword(const QString &vPassword) { - servicePass(encryptString(vPassword)); + servicePass(hashedPassword(vPassword, true)); } + +void View::VSettings::checkServicePasswordSet() +{ + bool ok; + isDefaultServicePassword(encryption::isDefaultServicePassword(servicePass(), ok)); + //DEBUG qDebug() << __FUNCTION__ << ok; + encryptionPass(ok); +} +