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 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 CParameterConnecter::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 CParameterConnecter::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 CParameterClient::PromptType::First:
134 case CParameterClient::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 CParameterClient::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));
The parameters of client.
the parameters of connecter interface.
CParameterClient * GetParameterClient()
Get CParameterClient.
virtual void slotSetParameterClient()
Call after set CParameterClient.
CParameterClient * m_pParameterClient