feather/src/dialog/PasswordChangeDialog.cpp

68 lines
2.5 KiB
C++
Raw Normal View History

// SPDX-License-Identifier: BSD-3-Clause
2023-01-02 19:30:11 +00:00
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
2021-06-27 11:46:32 +00:00
#include "PasswordChangeDialog.h"
#include "ui_PasswordChangeDialog.h"
2020-11-14 09:57:06 +00:00
#include <QMessageBox>
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)) {
2020-11-14 09:57:06 +00:00
QMessageBox::warning(this, "Error", "Incorrect password");
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 {
QMessageBox::warning(this, "Error", QString("Error: %1").arg(m_wallet->errorString()));
}
2021-06-27 12:25:10 +00:00
}
PasswordChangeDialog::~PasswordChangeDialog() = default;