2020-10-07 10:36:04 +00:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2024-01-01 17:07:58 +00:00
|
|
|
// SPDX-FileCopyrightText: 2020-2024 The Monero Project
|
2020-10-07 10:36:04 +00:00
|
|
|
|
2021-06-27 11:46:32 +00:00
|
|
|
#include "PasswordChangeDialog.h"
|
|
|
|
#include "ui_PasswordChangeDialog.h"
|
2020-10-07 10:36:04 +00:00
|
|
|
|
2023-09-12 14:15:40 +00:00
|
|
|
#include "Utils.h"
|
2020-10-07 10:36:04 +00:00
|
|
|
|
2020-11-14 09:57:06 +00:00
|
|
|
PasswordChangeDialog::PasswordChangeDialog(QWidget *parent, Wallet *wallet)
|
2021-10-22 17:19:56 +00:00
|
|
|
: WindowModalDialog(parent)
|
2020-10-07 10:36:04 +00:00
|
|
|
, ui(new Ui::PasswordChangeDialog)
|
2020-11-14 09:57:06 +00:00
|
|
|
, m_wallet(wallet)
|
2020-10-07 10:36:04 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2020-11-14 09:57:06 +00:00
|
|
|
|
2023-01-31 16:00:50 +00:00
|
|
|
bool noPassword = wallet->verifyPassword("");
|
2020-11-14 09:57:06 +00:00
|
|
|
QString warning_str = noPassword ? "Your wallet is not password protected. Use this dialog to add a password to your wallet." :
|
|
|
|
"Your wallet is password protected and encrypted. Use this dialog to change your password.";
|
|
|
|
ui->label_warning->setText(warning_str);
|
|
|
|
|
2023-03-29 09:26:10 +00:00
|
|
|
QPixmap pixmap = noPassword ? QPixmap(":/assets/images/unlock.svg") : QPixmap(":/assets/images/lock.svg");
|
2020-11-14 09:57:06 +00:00
|
|
|
ui->icon->setPixmap(pixmap.scaledToWidth(32, Qt::SmoothTransformation));
|
|
|
|
|
|
|
|
if (noPassword) {
|
|
|
|
ui->label_currentPassword->hide();
|
|
|
|
ui->lineEdit_currentPassword->hide();
|
|
|
|
}
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
connect(ui->lineEdit_newPassword, &QLineEdit::textChanged, this, &PasswordChangeDialog::passwordsMatch);
|
|
|
|
connect(ui->lineEdit_confirmPassword, &QLineEdit::textChanged, this, &PasswordChangeDialog::passwordsMatch);
|
|
|
|
|
2020-11-14 09:57:06 +00:00
|
|
|
connect(ui->btn_Cancel, &QPushButton::clicked, [this]{
|
|
|
|
this->reject();
|
|
|
|
});
|
|
|
|
connect(ui->btn_OK, &QPushButton::clicked, this, &PasswordChangeDialog::setPassword);
|
|
|
|
|
|
|
|
ui->label_match->setVisible(false);
|
|
|
|
|
2020-10-07 10:36:04 +00:00
|
|
|
this->adjustSize();
|
|
|
|
}
|
|
|
|
|
2020-11-14 09:57:06 +00:00
|
|
|
void PasswordChangeDialog::passwordsMatch() {
|
|
|
|
bool match = ui->lineEdit_newPassword->text() == ui->lineEdit_confirmPassword->text();
|
|
|
|
ui->btn_OK->setEnabled(match);
|
|
|
|
ui->label_match->setHidden(match);
|
2020-10-07 10:36:04 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 09:57:06 +00:00
|
|
|
void PasswordChangeDialog::setPassword() {
|
|
|
|
QString currentPassword = ui->lineEdit_currentPassword->text();
|
|
|
|
QString newPassword = ui->lineEdit_newPassword->text();
|
2020-10-07 10:36:04 +00:00
|
|
|
|
2023-01-31 16:00:50 +00:00
|
|
|
if (!m_wallet->verifyPassword(currentPassword)) {
|
2023-09-12 14:15:40 +00:00
|
|
|
Utils::showError(this, "Incorrect password", "");
|
2020-11-14 09:57:06 +00:00
|
|
|
ui->lineEdit_currentPassword->setText("");
|
|
|
|
ui->lineEdit_currentPassword->setFocus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-31 16:00:50 +00:00
|
|
|
if (m_wallet->setPassword(currentPassword, newPassword)) {
|
2020-11-14 09:57:06 +00:00
|
|
|
QMessageBox::information(this, "Information", "Password changed successfully");
|
|
|
|
this->accept();
|
|
|
|
}
|
|
|
|
else {
|
2023-09-12 14:15:40 +00:00
|
|
|
Utils::showError(this, "Unable to change password", m_wallet->errorString());
|
2020-11-14 09:57:06 +00:00
|
|
|
}
|
2021-06-27 12:25:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PasswordChangeDialog::~PasswordChangeDialog() = default;
|