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

Method SavePassword

Src/ParameterOperate.cpp:144–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

142}
143
144int CParameterOperate::SavePassword(const QString &szKey,
145 const QString &password,
146 QSettings &set, bool bSave)
147{
148 if(!bSave)
149 {
150 // Not save. then delete field from configure
151 set.remove(szKey);
152 set.remove(szKey + "_sum");
153 return 0;
154 }
155
156 QByteArray encryptPassword;
157 RabbitCommon::CEncrypt e;
158 std::string key;
159 if(GetPluginParameters()) {
160 key = GetPluginParameters()->GetEncryptKey().toStdString();
161 if(key.empty())
162 {
163 switch (GetPluginParameters()->GetPromptType()) {
164 case CParameterPlugin::PromptType::First:
165 {
166 int nCount = GetPluginParameters()->GetPromptCount();
167 if(nCount >= 1)
168 break;
169 GetPluginParameters()->SetPromptCount(nCount + 1);
170 QString szKey;
171 CDlgInputPassword dlg(GetPluginParameters()->GetViewPassowrd(), true);
172 if(QDialog::Accepted != dlg.exec())
173 break;
174 szKey = dlg.GetPassword();
175 GetPluginParameters()->SetEncryptKey(szKey);
176 key = szKey.toStdString();
177 break;
178 }
179 case CParameterPlugin::PromptType::No:
180 break;
181 }
182 }
183 }
184 if(key.empty()) {
185 // Use random password
186 QSettings s(RabbitCommon::CDir::Instance()->GetFileUserConfigure(), QSettings::IniFormat);
187 QByteArray baRandom = s.value("Plugin/Password/Random").toByteArray();
188 QString szRandom;
189 if(baRandom.isEmpty()) {
190 // Generate a random password of a specified length
191 szRandom = RabbitCommon::CPasswordGenerator::GeneratePassword().c_str();
192 RabbitCommon::CEncrypt eRandom;
193 QByteArray baRandom;
194 eRandom.Encode(szRandom, baRandom);
195 s.setValue("Plugin/Password/Random", baRandom);
196 } else {
197 RabbitCommon::CEncrypt eRandom;
198 eRandom.Dencode(baRandom, szRandom);
199 }
200 e.SetPassword(szRandom.toStdString().c_str());
201 } else {

Callers 1

saveCredentialsMethod · 0.80

Calls 8

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

Tested by

no test coverage detected