Skip to content

Commit 60adb21

Browse files
committed
Optionally allow AskPassphraseDialog to output the passphrase
1 parent bc6d8a3 commit 60adb21

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

src/qt/askpassphrasedialog.cpp

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
#include <QMessageBox>
1919
#include <QPushButton>
2020

21-
AskPassphraseDialog::AskPassphraseDialog(Mode _mode, QWidget *parent) :
21+
AskPassphraseDialog::AskPassphraseDialog(Mode _mode, QWidget *parent, SecureString* passphrase_out) :
2222
QDialog(parent),
2323
ui(new Ui::AskPassphraseDialog),
2424
mode(_mode),
2525
model(nullptr),
26-
fCapsLock(false)
26+
fCapsLock(false),
27+
m_passphrase_out(passphrase_out)
2728
{
2829
ui->setupUi(this);
2930

@@ -90,7 +91,7 @@ void AskPassphraseDialog::setModel(WalletModel *_model)
9091
void AskPassphraseDialog::accept()
9192
{
9293
SecureString oldpass, newpass1, newpass2;
93-
if(!model)
94+
if (!model && mode != Encrypt)
9495
return;
9596
oldpass.reserve(MAX_PASSPHRASE_SIZE);
9697
newpass1.reserve(MAX_PASSPHRASE_SIZE);
@@ -119,24 +120,33 @@ void AskPassphraseDialog::accept()
119120
{
120121
if(newpass1 == newpass2)
121122
{
122-
if(model->setWalletEncrypted(true, newpass1))
123-
{
124-
QMessageBox::warning(this, tr("Wallet encrypted"),
123+
QString encryption_reminder = tr("Remember that encrypting your wallet cannot fully protect "
124+
"your bitcoins from being stolen by malware infecting your computer.");
125+
if (m_passphrase_out) {
126+
m_passphrase_out->assign(newpass1);
127+
QMessageBox::warning(this, tr("Wallet to be encrypted"),
125128
"<qt>" +
126-
tr("Your wallet is now encrypted. "
127-
"Remember that encrypting your wallet cannot fully protect "
128-
"your bitcoins from being stolen by malware infecting your computer.") +
129-
"<br><br><b>" +
130-
tr("IMPORTANT: Any previous backups you have made of your wallet file "
131-
"should be replaced with the newly generated, encrypted wallet file. "
132-
"For security reasons, previous backups of the unencrypted wallet file "
133-
"will become useless as soon as you start using the new, encrypted wallet.") +
129+
tr("Your wallet is about to be encrypted. ") + encryption_reminder +
134130
"</b></qt>");
135-
}
136-
else
137-
{
138-
QMessageBox::critical(this, tr("Wallet encryption failed"),
139-
tr("Wallet encryption failed due to an internal error. Your wallet was not encrypted."));
131+
} else {
132+
assert(model != nullptr);
133+
if(model->setWalletEncrypted(true, newpass1))
134+
{
135+
QMessageBox::warning(this, tr("Wallet encrypted"),
136+
"<qt>" +
137+
tr("Your wallet is now encrypted. ") + encryption_reminder +
138+
"<br><br><b>" +
139+
tr("IMPORTANT: Any previous backups you have made of your wallet file "
140+
"should be replaced with the newly generated, encrypted wallet file. "
141+
"For security reasons, previous backups of the unencrypted wallet file "
142+
"will become useless as soon as you start using the new, encrypted wallet.") +
143+
"</b></qt>");
144+
}
145+
else
146+
{
147+
QMessageBox::critical(this, tr("Wallet encryption failed"),
148+
tr("Wallet encryption failed due to an internal error. Your wallet was not encrypted."));
149+
}
140150
}
141151
QDialog::accept(); // Success
142152
}

src/qt/askpassphrasedialog.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include <QDialog>
99

10+
#include <support/allocators/secure.h>
11+
1012
class WalletModel;
1113

1214
namespace Ui {
@@ -27,7 +29,7 @@ class AskPassphraseDialog : public QDialog
2729
Decrypt /**< Ask passphrase and decrypt wallet */
2830
};
2931

30-
explicit AskPassphraseDialog(Mode mode, QWidget *parent);
32+
explicit AskPassphraseDialog(Mode mode, QWidget *parent, SecureString* passphrase_out = nullptr);
3133
~AskPassphraseDialog();
3234

3335
void accept();
@@ -39,6 +41,7 @@ class AskPassphraseDialog : public QDialog
3941
Mode mode;
4042
WalletModel *model;
4143
bool fCapsLock;
44+
SecureString* m_passphrase_out;
4245

4346
private Q_SLOTS:
4447
void textChanged();

0 commit comments

Comments
 (0)