3#include <QLoggingCategory>
4#include <QCryptographicHash>
7#include "RabbitCommonEncrypt.h"
8#include "RabbitCommonTools.h"
9#include "DlgInputPassword.h"
10#include "ParameterOperate.h"
12static Q_LOGGING_CATEGORY(log,
"Parameter.Operate")
17 , m_pParameterPlugin(
nullptr)
20 check = connect(
this, SIGNAL(sigSetGlobalParameters()),
21 this, SLOT(slotSetGlobalParameters()));
26 check = connect(m_Parent, SIGNAL(sigSetGlobalParameters()),
27 this, SIGNAL(sigSetGlobalParameters()));
51QByteArray CParameterOperate::PasswordSum(
const std::string &password,
52 const std::string &key)
54 std::string pw =
"RabbitRemoteControl";
55 QCryptographicHash sum(QCryptographicHash::Md5);
57#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
59 sum.addData(password.c_str(), password.length());
60 sum.addData(pw.c_str(), pw.length());
62 sum.addData(key.c_str(), key.length());
65 sum.addData(QByteArrayView(password.c_str(), password.length()));
66 sum.addData(QByteArrayView(pw.c_str(), pw.length()));
68 sum.addData(QByteArrayView(key.c_str(), key.length()));
73int CParameterOperate::LoadPassword(
const QString &szTitle,
78 QByteArray sum = set.value(szKey +
"_sum").toByteArray();
79 QByteArray pwByte = set.value(szKey).toByteArray();
82 RabbitCommon::CEncrypt e;
88 e.SetPassword(key.c_str());
90 if(!e.Dencode(pwByte, password)
91 && PasswordSum(password.toStdString(), key) == sum)
94 qDebug(log) <<
"Password don't dencode or sum is error";
96 if(QDialog::Accepted != d.exec())
101 CDlgInputPassword::InputType t;
102 int nRet = d.GetValue(t, password);
103 if(nRet)
return nRet;
104 if(CDlgInputPassword::InputType::Password == t)
107 return LoadPassword(szTitle, szKey, password, set);
110int CParameterOperate::SavePassword(
const QString &szKey,
111 const QString &password,
112 QSettings &set,
bool bSave)
117 set.remove(szKey +
"_sum");
121 QByteArray encryptPassword;
122 RabbitCommon::CEncrypt e;
127 case CParameterPlugin::PromptType::First:
134 case CParameterPlugin::PromptType::Always:
137 CDlgInputPassword::InputType t = CDlgInputPassword::InputType::Encrypt;
139 if(QDialog::Accepted == dlg.exec())
140 dlg.GetValue(t, szKey);
141 if(CDlgInputPassword::InputType::Encrypt == t)
145 case CParameterPlugin::PromptType::No:
149 e.SetPassword(key.c_str());
150 if(password.isEmpty())
152 e.Encode(password, encryptPassword);
153 set.setValue(szKey, encryptPassword);
154 set.setValue(szKey +
"_sum", PasswordSum(password.toStdString(), key));
Operational parameter interface.
void sigSetGlobalParameters()
Only used by this class.
virtual void slotSetGlobalParameters()
Call after set CParameterPlugin.
CParameterPlugin * GetGlobalParameters()
Get CParameterPlugin.
CParameterPlugin * m_pParameterPlugin
Global parameters of plugins.