bool PrivacyForm::setToxPassword() { Core* core = Core::getInstance(); SetPasswordDialog* dialog; QString body = tr("Please set your new data file password."); if (core->isPasswordSet(Core::ptHistory)) dialog = new SetPasswordDialog(body, tr("Use chat history password", "pushbutton text"), this); else dialog = new SetPasswordDialog(body, QString(), this); if (int r = dialog->exec()) { QString newpw = dialog->getPassword(); delete dialog; if (r == SetPasswordDialog::Tertiary) core->useOtherPassword(Core::ptMain); else core->setPassword(newpw, Core::ptMain); Settings::getInstance().setEncryptTox(true); core->saveConfiguration(); return true; } else { delete dialog; return false; } }
bool PrivacyForm::setChatLogsPassword() { Core* core = Core::getInstance(); SetPasswordDialog* dialog; // check if an encrypted history exists because it was disabled earlier, and use it if possible QString path = HistoryKeeper::getHistoryPath(QString(), 1); QByteArray salt = core->getSaltFromFile(path); bool haveEncHist = salt.size() > 0; QString body = tr("Please set your new chat history password."); if (haveEncHist) body += "\n\n" + tr("It appears you have an unused encrypted chat history; if the password matches, it will be added to your current history."); if (core->isPasswordSet(Core::ptMain)) dialog = new SetPasswordDialog(body, tr("Use data file password", "pushbutton text"), this); else dialog = new SetPasswordDialog(body, QString(), this); do { int r = dialog->exec(); if (r == QDialog::Rejected) break; QList<HistoryKeeper::HistMessage> oldMessages = HistoryKeeper::exportMessagesDeleteFile(); QString newpw = dialog->getPassword(); if (r == SetPasswordDialog::Tertiary) core->useOtherPassword(Core::ptHistory); else if (haveEncHist) core->setPassword(newpw, Core::ptHistory, reinterpret_cast<uint8_t*>(salt.data())); else core->setPassword(newpw, Core::ptHistory); if (!haveEncHist || HistoryKeeper::checkPassword(1)) { Settings::getInstance().setEncryptLogs(true); HistoryKeeper::getInstance()->importMessages(oldMessages); if (haveEncHist) { Widget::getInstance()->reloadHistory(); GUI::showWarning(tr("Successfully decrypted old chat history","popup title"), tr("You have succesfully decrypted the old chat history, and it has been added to your current history and re-encrypted.", "popup text")); } delete dialog; return true; } else { if (GUI::askQuestion(tr("Old encrypted chat history", "popup title"), tr("There is currently an unused encrypted chat history, but the password you just entered doesn't match.\n\nIf you don't care about the old history, you may click Ok to delete it and use the password you just entered.\nOtherwise, hit cancel to try again.", "This happens when enabling encryption after previously \"Disabling History\""), false, true, false)) if (GUI::askQuestion(tr("Old encrypted chat history", "popup title"), tr("Are you absolutely sure you want to lose the unused encrypted chat history?", "secondary popup"))) haveEncHist = false; // logically this is really just a `break`, but conceptually this is more accurate } } while (haveEncHist); delete dialog; return false; }
void ProfileForm::onChangePassClicked() { SetPasswordDialog* dialog = new SetPasswordDialog(tr("Please enter a new password."), QString(), 0); int r = dialog->exec(); if (r == QDialog::Rejected) return; QString newPass = dialog->getPassword(); Nexus::getProfile()->setPassword(newPass); }
void ProfileForm::onChangePassClicked() { Profile* p = Nexus::getProfile(); SetPasswordDialog* dialog = new SetPasswordDialog(tr("Please enter a new password."), QString(), 0); int r = dialog->exec(); if (r == QDialog::Rejected) return; QString newPass = dialog->getPassword(); QString errorMsg = p->setPassword(newPass); if (!errorMsg.isEmpty()) { GUI::showInfo(tr("Couldn't change password"), errorMsg); } }