From: tobtoht Date: Sat, 30 Dec 2023 14:45:54 +0000 (+0100) Subject: view-only: confirm password X-Git-Url: https://git.nutra.tk/v1?a=commitdiff_plain;h=a7d58775c07963f5eec890c7966e408dc3ab9008;p=gamesguru%2Ffeather.git view-only: confirm password --- diff --git a/src/dialog/PasswordSetDialog.cpp b/src/dialog/PasswordSetDialog.cpp new file mode 100644 index 00000000..5063782c --- /dev/null +++ b/src/dialog/PasswordSetDialog.cpp @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: BSD-3-Clause +// SPDX-FileCopyrightText: 2020-2023 The Monero Project + +#include "PasswordSetDialog.h" +#include "ui_PasswordSetDialog.h" + +#include "utils/Icons.h" + +PasswordSetDialog::PasswordSetDialog(const QString &helpText, QWidget *parent) + : WindowModalDialog(parent) + , ui(new Ui::PasswordSetDialog) +{ + ui->setupUi(this); + + ui->frame_info->setInfo(icons()->icon("lock"), helpText); + + connect(ui->widget_password, &PasswordSetWidget::passwordEntryChanged, [this]{ + bool passwordsMatch = ui->widget_password->passwordsMatch(); + + QPushButton *okButton = ui->buttonBox->button(QDialogButtonBox::Ok); + if (okButton) { + okButton->setEnabled(passwordsMatch); + } + }); + + this->adjustSize(); +} + +QString PasswordSetDialog::password() { + return ui->widget_password->password(); +} + +PasswordSetDialog::~PasswordSetDialog() = default; \ No newline at end of file diff --git a/src/dialog/PasswordSetDialog.h b/src/dialog/PasswordSetDialog.h new file mode 100644 index 00000000..8a89e5cf --- /dev/null +++ b/src/dialog/PasswordSetDialog.h @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: BSD-3-Clause +// SPDX-FileCopyrightText: 2020-2023 The Monero Project + +#ifndef FEATHER_PASSWORDSETDIALOG_H +#define FEATHER_PASSWORDSETDIALOG_H + +#include + +#include "components.h" + +namespace Ui { + class PasswordSetDialog; +} + +class PasswordSetDialog : public WindowModalDialog +{ +Q_OBJECT + +public: + explicit PasswordSetDialog(const QString &helpText, QWidget *parent = nullptr); + ~PasswordSetDialog() override; + + QString password(); + +private: + QScopedPointer ui; +}; + + +#endif //FEATHER_PASSWORDSETDIALOG_H diff --git a/src/dialog/PasswordSetDialog.ui b/src/dialog/PasswordSetDialog.ui new file mode 100644 index 00000000..c6e7ce7b --- /dev/null +++ b/src/dialog/PasswordSetDialog.ui @@ -0,0 +1,114 @@ + + + PasswordSetDialog + + + + 0 + 0 + 579 + 240 + + + + Set Password + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 10 + + + + + + + + + 0 + 0 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Ok + + + + + + + + InfoFrame + QFrame +
components.h
+ 1 +
+ + PasswordSetWidget + QWidget +
widgets/PasswordSetWidget.h
+ 1 +
+
+ + + + buttonBox + accepted() + PasswordSetDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + PasswordSetDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +
diff --git a/src/dialog/ViewOnlyDialog.cpp b/src/dialog/ViewOnlyDialog.cpp index d67685d4..76cd874f 100644 --- a/src/dialog/ViewOnlyDialog.cpp +++ b/src/dialog/ViewOnlyDialog.cpp @@ -12,6 +12,7 @@ #include "utils/Utils.h" #include "WalletManager.h" #include "qrcode/QrCode.h" +#include "dialog/PasswordSetDialog.h" #include "dialog/QrCodeDialog.h" ViewOnlyDialog::ViewOnlyDialog(Wallet *wallet, QWidget *parent) @@ -43,20 +44,18 @@ ViewOnlyDialog::ViewOnlyDialog(Wallet *wallet, QWidget *parent) void ViewOnlyDialog::onWriteViewOnlyWallet(){ QString fn = QFileDialog::getSaveFileName(this, "Save .keys wallet file", Utils::defaultWalletDir(), "Monero wallet (*.keys)"); - if(fn.isEmpty()) return; - if(!fn.endsWith(".keys")) fn += ".keys"; - - QString passwd; - QInputDialog passwordDialog(this); - passwordDialog.setInputMode(QInputDialog::TextInput); - passwordDialog.setTextEchoMode(QLineEdit::Password); - passwordDialog.setWindowTitle("View-Only wallet password"); - passwordDialog.setLabelText("Protect this view-only wallet with a password?"); - passwordDialog.resize(300, 100); - if((bool)passwordDialog.exec()) - passwd = passwordDialog.textValue(); - - m_wallet->createViewOnly(fn, passwd); + if (fn.isEmpty()) { + return; + } + if (!fn.endsWith(".keys")) { + fn += ".keys"; + } + + PasswordSetDialog dialog("Set a password for the view-only wallet", this); + dialog.exec(); + QString password = dialog.password(); + + m_wallet->createViewOnly(fn, password); QMessageBox::information(this, "Information", "View-only wallet successfully written to disk."); } diff --git a/src/widgets/PasswordSetWidget.cpp b/src/widgets/PasswordSetWidget.cpp new file mode 100644 index 00000000..0c16b141 --- /dev/null +++ b/src/widgets/PasswordSetWidget.cpp @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: BSD-3-Clause +// SPDX-FileCopyrightText: 2020-2023 The Monero Project + +#include "PasswordSetWidget.h" +#include "ui_PasswordSetWidget.h" + +PasswordSetWidget::PasswordSetWidget(QWidget *parent) + : QWidget(parent) + , ui(new Ui::PasswordSetWidget) +{ + ui->setupUi(this); + + connect(ui->line_password, &QLineEdit::textChanged, this, &PasswordSetWidget::onPasswordEntryChanged); + connect(ui->line_confirmPassword, &QLineEdit::textChanged, this, &PasswordSetWidget::onPasswordEntryChanged); + + ui->label_match->setHidden(true); +} + +QString PasswordSetWidget::password() { + if (!this->passwordsMatch()) { + return {}; + } + + return ui->line_password->text(); +} + +bool PasswordSetWidget::passwordsMatch() { + return ui->line_password->text() == ui->line_confirmPassword->text(); +} + +void PasswordSetWidget::resetFields() { + ui->line_password->setText(""); + ui->line_confirmPassword->setText(""); +} + +void PasswordSetWidget::onPasswordEntryChanged() { + ui->label_match->setHidden(this->passwordsMatch()); + emit passwordEntryChanged(); +} + +PasswordSetWidget::~PasswordSetWidget() = default; \ No newline at end of file diff --git a/src/widgets/PasswordSetWidget.h b/src/widgets/PasswordSetWidget.h new file mode 100644 index 00000000..badd372e --- /dev/null +++ b/src/widgets/PasswordSetWidget.h @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: BSD-3-Clause +// SPDX-FileCopyrightText: 2020-2023 The Monero Project + +#ifndef FEATHER_PASSWORDSETWIDGET_H +#define FEATHER_PASSWORDSETWIDGET_H + +#include + +namespace Ui { + class PasswordSetWidget; +} + +class PasswordSetWidget : public QWidget +{ +Q_OBJECT + +public: + explicit PasswordSetWidget(QWidget *parent = nullptr); + ~PasswordSetWidget() override; + + QString password(); + bool passwordsMatch(); + void resetFields(); + +signals: + void passwordEntryChanged(); + +private slots: + void onPasswordEntryChanged(); + +private: + QScopedPointer ui; +}; + + +#endif //FEATHER_PASSWORDSETWIDGET_H diff --git a/src/wizard/PageSetPassword.ui b/src/widgets/PasswordSetWidget.ui similarity index 51% copy from src/wizard/PageSetPassword.ui copy to src/widgets/PasswordSetWidget.ui index b9175d3a..ddcf212e 100644 --- a/src/wizard/PageSetPassword.ui +++ b/src/widgets/PasswordSetWidget.ui @@ -1,47 +1,33 @@ - PageSetPassword - + PasswordSetWidget + 0 0 - 431 - 232 + 485 + 153 - WizardPage + Form + + 0 + + + 0 + + + 0 + + + 0 + - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 10 - - - - - - + Password: @@ -49,13 +35,19 @@ + + + 300 + 0 + + QLineEdit::Password - + Confirm Password: @@ -63,21 +55,26 @@ + + + 300 + 0 + + QLineEdit::Password + + + + Passwords do not match + + + - - - InfoFrame - QFrame -
components.h
- 1 -
-
diff --git a/src/wizard/PageSetPassword.cpp b/src/wizard/PageSetPassword.cpp index 726cfcb2..65f53ff2 100644 --- a/src/wizard/PageSetPassword.cpp +++ b/src/wizard/PageSetPassword.cpp @@ -17,10 +17,7 @@ PageSetPassword::PageSetPassword(WizardFields *fields, QWidget *parent) ui->frame_password->setInfo(icons()->icon("lock"), "Choose a password to encrypt your wallet keys."); - connect(ui->line_password, &QLineEdit::textChanged, [this]{ - this->completeChanged(); - }); - connect(ui->line_confirmPassword, &QLineEdit::textChanged, [this]{ + connect(ui->widget_password, &PasswordSetWidget::passwordEntryChanged, [this]{ this->completeChanged(); }); @@ -29,12 +26,11 @@ PageSetPassword::PageSetPassword(WizardFields *fields, QWidget *parent) void PageSetPassword::initializePage() { this->setTitle(m_fields->modeText); - ui->line_password->setText(""); - ui->line_confirmPassword->setText(""); + ui->widget_password->resetFields(); } bool PageSetPassword::validatePage() { - m_fields->password = ui->line_password->text(); + m_fields->password = ui->widget_password->password(); emit createWallet(); return true; } @@ -44,5 +40,5 @@ int PageSetPassword::nextId() const { } bool PageSetPassword::isComplete() const { - return ui->line_password->text() == ui->line_confirmPassword->text(); + return ui->widget_password->passwordsMatch(); } diff --git a/src/wizard/PageSetPassword.ui b/src/wizard/PageSetPassword.ui index b9175d3a..cae972eb 100644 --- a/src/wizard/PageSetPassword.ui +++ b/src/wizard/PageSetPassword.ui @@ -41,32 +41,7 @@ - - - Password: - - - - - - - QLineEdit::Password - - - - - - - Confirm Password: - - - - - - - QLineEdit::Password - - + @@ -77,6 +52,12 @@
components.h
1 + + PasswordSetWidget + QWidget +
widgets/PasswordSetWidget.h
+ 1 +