MCPcopy Create free account
hub / github.com/KangLin/RabbitRemoteControl / LoadPassword

Method LoadPassword

Src/ParameterOperate.cpp:82–142  ·  view source on GitHub ↗

! * \brief Restore password * \details * if the encryption key is incorrect, Password is set to empty. * it proceeds to the normal password entry. * flow chart: \image html docs/Image/RestorePassword.svg * \see https://github.com/KangLin/RabbitRemoteControl/issues/79 */

Source from the content-addressed store, hash-verified

80 * \see https://github.com/KangLin/RabbitRemoteControl/issues/79
81 */
82int CParameterOperate::LoadPassword(const QString &szTitle,
83 const QString &szKey,
84 QString &password,
85 QSettings &set)
86{
87 QByteArray sum = set.value(szKey + "_sum").toByteArray();
88 QByteArray pwByte = set.value(szKey).toByteArray();
89 if(pwByte.isEmpty())
90 return 0;
91 RabbitCommon::CEncrypt e;
92
93 std::string key;
94 if(GetPluginParameters())
95 key = GetPluginParameters()->GetEncryptKey().toStdString();
96 if(key.empty()) {
97 // Load readom password from config file
98 QSettings s(RabbitCommon::CDir::Instance()->GetFileUserConfigure(), QSettings::IniFormat);
99 QByteArray baRandom = s.value("Plugin/Password/Random").toByteArray();
100 QString szRandom;
101 if(!baRandom.isEmpty()) {
102 RabbitCommon::CEncrypt eRandom;
103 eRandom.Dencode(baRandom, szRandom);
104 }
105 if(!szRandom.isEmpty())
106 e.SetPassword(szRandom.toStdString().c_str());
107 } else {
108 e.SetPassword(key.c_str());
109 }
110
111 if(!e.Dencode(pwByte, password)
112 && PasswordSum(password.toStdString(), key) == sum)
113 return 0;
114
115 qDebug(log) << "Password don't dencode or sum is error";
116 if(key.empty() && GetPluginParameters()) {
117 switch (GetPluginParameters()->GetPromptType()) {
118 case CParameterPlugin::PromptType::First:
119 {
120 int nCount = GetPluginParameters()->GetPromptCount();
121 if(nCount >= 1)
122 return -1;
123 GetPluginParameters()->SetPromptCount(nCount + 1);
124 break;
125 }
126 case CParameterPlugin::PromptType::No:
127 default:
128 return -1;
129 }
130
131 CDlgInputPassword d(GetPluginParameters()->GetViewPassowrd(), false);
132 if(QDialog::Accepted != d.exec())
133 return -1;
134
135 key = d.GetPassword().toStdString();
136 if(key.empty()) return -1;
137
138 GetPluginParameters()->SetEncryptKey(key.c_str());
139 return LoadPassword(szTitle, szKey, password, set);

Callers 1

getCredentialsMethod · 0.80

Calls 8

GetPromptTypeMethod · 0.80
GetPromptCountMethod · 0.80
SetPromptCountMethod · 0.80
GetViewPassowrdMethod · 0.80
SetEncryptKeyMethod · 0.80
isEmptyMethod · 0.45
SetPasswordMethod · 0.45
GetPasswordMethod · 0.45

Tested by

no test coverage detected