feather/src/dialog/PasswordChangeDialog.cpp

68 lines
2.4 KiB
C++
Raw Normal View History

// SPDX-License-Identifier: BSD-3-Clause
2024-01-01 17:07:58 +00:00
// SPDX-FileCopyrightText: 2020-2024 The Monero Project
2021-06-27 11:46:32 +00:00
#include "PasswordChangeDialog.h"
#include "ui_PasswordChangeDialog.h"
#include "Utils.h"
2020-11-14 09:57:06 +00:00
PasswordChangeDialog::PasswordChangeDialog(QWidget *parent, Wallet *wallet)
2021-10-22 17:19:56 +00:00
: WindowModalDialog(parent)
, ui(new Ui::PasswordChangeDialog)
2020-11-14 09:57:06 +00:00
, m_wallet(wallet)
{
ui->setupUi(this);
2020-11-14 09:57:06 +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();
}
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);
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-11-14 09:57:06 +00:00
void PasswordChangeDialog::setPassword() {
QString currentPassword = ui->lineEdit_currentPassword->text();
QString newPassword = ui->lineEdit_newPassword->text();
if (!m_wallet->verifyPassword(currentPassword)) {
Utils::showError(this, "Incorrect password", "");
2020-11-14 09:57:06 +00:00
ui->lineEdit_currentPassword->setText("");
ui->lineEdit_currentPassword->setFocus();
return;
}
if (m_wallet->setPassword(currentPassword, newPassword)) {
2020-11-14 09:57:06 +00:00
QMessageBox::information(this, "Information", "Password changed successfully");
this->accept();
}
else {
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;