3#include <QLoggingCategory>
4#include <QCryptographicHash>
7#include "RabbitCommonEncrypt.h"
8#include "RabbitCommonTools.h"
9#include "DlgInputPassword.h"
10#include "ParameterConnecter.h"
12static Q_LOGGING_CATEGORY(log,
"Client.Parameter.Connecter")
17 m_pParameterClient(
nullptr)
20 check = connect(
this, SIGNAL(sigSetParameterClient()),
21 this, SLOT(slotSetParameterClient()));
26 check = connect(m_Parent, SIGNAL(sigSetParameterClient()),
27 this, SIGNAL(sigSetParameterClient()));
42 emit sigSetParameterClient();
51QByteArray CParameterConnecter::PasswordSum(
const std::string &password,
52 const std::string &key)
54 QCryptographicHash sum(QCryptographicHash::Md5);
56 sum.addData(password.c_str(), password.length());
57 std::string pw =
"RabbitRemoteControl";
58 sum.addData(pw.c_str(), pw.length());
60 sum.addData(key.c_str(), key.length());
64int CParameterConnecter::LoadPassword(
const QString &szTitle,
69 QByteArray sum = set.value(szKey +
"_sum").toByteArray();
70 QByteArray pwByte = set.value(szKey).toByteArray();
73 RabbitCommon::CEncrypt e;
79 e.SetPassword(key.c_str());
81 if(!e.Dencode(pwByte, password)
82 && PasswordSum(password.toStdString(), key) == sum)
85 qDebug(log) <<
"Password don't dencode or sum is error";
87 if(QDialog::Accepted != d.exec())
92 CDlgInputPassword::InputType t;
93 int nRet = d.GetValue(t, password);
95 if(CDlgInputPassword::InputType::Password == t)
98 return LoadPassword(szTitle, szKey, password, set);
101int CParameterConnecter::SavePassword(
const QString &szKey,
102 const QString &password,
103 QSettings &set,
bool bSave)
108 set.remove(szKey +
"_sum");
112 QByteArray encryptPassword;
113 RabbitCommon::CEncrypt e;
118 case CParameterClient::PromptType::First:
125 case CParameterClient::PromptType::Always:
128 CDlgInputPassword::InputType t = CDlgInputPassword::InputType::Encrypt;
130 if(QDialog::Accepted == dlg.exec())
131 dlg.GetValue(t, szKey);
132 if(CDlgInputPassword::InputType::Encrypt == t)
136 case CParameterClient::PromptType::No:
140 e.SetPassword(key.c_str());
141 if(password.isEmpty())
143 e.Encode(password, encryptPassword);
144 set.setValue(szKey, encryptPassword);
145 set.setValue(szKey +
"_sum", PasswordSum(password.toStdString(), key));
The parameters of client.
the parameters of connecter interface.
CParameterClient * GetParameterClient()
Get CParameterClient.
virtual void slotSetParameterClient()
Call after set CParameterClient.
CParameterClient * m_pParameterClient