Index: sources/view/settings/VSettings.cpp =================================================================== diff -u -r7ec98d237f871e5d1206809d309da6d57a086d28 -rc73feffa73c7fe073a7a7581144f5806dfc91beb --- sources/view/settings/VSettings.cpp (.../VSettings.cpp) (revision 7ec98d237f871e5d1206809d309da6d57a086d28) +++ sources/view/settings/VSettings.cpp (.../VSettings.cpp) (revision c73feffa73c7fe073a7a7581144f5806dfc91beb) @@ -22,6 +22,7 @@ #include "GuiController.h" #include "MSettings.h" #include "Settings.h" +#include VIEW_DEF_CLASS(VSettings) @@ -126,8 +127,6 @@ 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. - isPasswordSet ( ! isPasswordDefault() ); - adjustment(true); } @@ -268,70 +267,41 @@ return ok; } -#include - -/*! - * \brief VSettings::encryptString - * \details encrypts the string vString with an algorithm - * \param vString - the string to be encrypted. - * \return encrypted string - */ -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 : ""; } /*! - * \brief View::VSettings::isPasswordMatch + * \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::isPasswordMatch(const QString &vPassword) { - return _servicePass == encryptString(vPassword); +bool View::VSettings::isServicePasswordMatch(const QString &vPassword) { + + qDebug() << __FUNCTION__ << hashedPassword(vPassword, true); + return _servicePass == hashedPassword(vPassword, true); } /*! - * \brief View::VSettings::updatePassword + * \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::updatePassword(const QString &vPassword) +void View::VSettings::updateServicePassword(const QString &vPassword) { - servicePass(encryptString(vPassword)); + servicePass(hashedPassword(vPassword, true)); } -/*! - * \brief View::VSettings::isPasswordDefault - * \details Checks if the current service password is the default password - * \note It is being used to force the user/manufacturer to set the service password. - * \return true if the service password is the default. - */ -bool View::VSettings::isPasswordDefault() +void View::VSettings::checkServicePasswordSet() { - return servicePass() == defaultPassword(); + bool ok; + isDefaultServicePassword(encryption::isDefaultServicePassword(servicePass(), ok)); + qDebug() << __FUNCTION__ << ok; + encryptionPass(ok); } -/*! - * \brief View::VSettings::defaultPassword - * \details The default password which will be used as an indication that the service password has not been set yet. - * \return the default password as encrypted string. - */ -QString View::VSettings::defaultPassword() -{ - QString _A1 = "tal"; - QString _S1 = QString("%1").arg(_A1 ).prepend("A" ); - QString _S2 = QString("%1").arg(_A1 ).prepend("Ma" ); - QString _S3 = QString("%1").arg(10*2+2 ).append ("leh" ); - return encryptString(( QStringList() << _S1 << _S2 << _S3 ).join('.')); -}