Changeset View
Changeset View
Standalone View
Standalone View
src/qt/askpassphrasedialog.cpp
Show All 11 Lines | |||||
#include <qt/guiconstants.h> | #include <qt/guiconstants.h> | ||||
#include <qt/walletmodel.h> | #include <qt/walletmodel.h> | ||||
#include <support/allocators/secure.h> | #include <support/allocators/secure.h> | ||||
#include <QKeyEvent> | #include <QKeyEvent> | ||||
#include <QMessageBox> | #include <QMessageBox> | ||||
#include <QPushButton> | #include <QPushButton> | ||||
AskPassphraseDialog::AskPassphraseDialog(Mode _mode, QWidget *parent) | AskPassphraseDialog::AskPassphraseDialog(Mode _mode, QWidget *parent, | ||||
SecureString *passphrase_out) | |||||
: QDialog(parent), ui(new Ui::AskPassphraseDialog), mode(_mode), | : QDialog(parent), ui(new Ui::AskPassphraseDialog), mode(_mode), | ||||
model(nullptr), fCapsLock(false) { | model(nullptr), fCapsLock(false), m_passphrase_out(passphrase_out) { | ||||
ui->setupUi(this); | ui->setupUi(this); | ||||
ui->passEdit1->setMinimumSize(ui->passEdit1->sizeHint()); | ui->passEdit1->setMinimumSize(ui->passEdit1->sizeHint()); | ||||
ui->passEdit2->setMinimumSize(ui->passEdit2->sizeHint()); | ui->passEdit2->setMinimumSize(ui->passEdit2->sizeHint()); | ||||
ui->passEdit3->setMinimumSize(ui->passEdit3->sizeHint()); | ui->passEdit3->setMinimumSize(ui->passEdit3->sizeHint()); | ||||
ui->passEdit1->setMaxLength(MAX_PASSPHRASE_SIZE); | ui->passEdit1->setMaxLength(MAX_PASSPHRASE_SIZE); | ||||
ui->passEdit2->setMaxLength(MAX_PASSPHRASE_SIZE); | ui->passEdit2->setMaxLength(MAX_PASSPHRASE_SIZE); | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
void AskPassphraseDialog::setModel(WalletModel *_model) { | void AskPassphraseDialog::setModel(WalletModel *_model) { | ||||
this->model = _model; | this->model = _model; | ||||
} | } | ||||
void AskPassphraseDialog::accept() { | void AskPassphraseDialog::accept() { | ||||
SecureString oldpass, newpass1, newpass2; | SecureString oldpass, newpass1, newpass2; | ||||
if (!model) { | if (!model && mode != Encrypt) { | ||||
return; | return; | ||||
} | } | ||||
oldpass.reserve(MAX_PASSPHRASE_SIZE); | oldpass.reserve(MAX_PASSPHRASE_SIZE); | ||||
newpass1.reserve(MAX_PASSPHRASE_SIZE); | newpass1.reserve(MAX_PASSPHRASE_SIZE); | ||||
newpass2.reserve(MAX_PASSPHRASE_SIZE); | newpass2.reserve(MAX_PASSPHRASE_SIZE); | ||||
// TODO: get rid of this .c_str() by implementing | // TODO: get rid of this .c_str() by implementing | ||||
// SecureString::operator=(std::string) | // SecureString::operator=(std::string) | ||||
// Alternately, find a way to make this input mlock()'d to begin with. | // Alternately, find a way to make this input mlock()'d to begin with. | ||||
Show All 13 Lines | switch (mode) { | ||||
this, tr("Confirm wallet encryption"), | this, tr("Confirm wallet encryption"), | ||||
tr("Warning: If you encrypt your wallet and lose your " | tr("Warning: If you encrypt your wallet and lose your " | ||||
"passphrase, you will <b>LOSE ALL OF YOUR BITCOINS</b>!") + | "passphrase, you will <b>LOSE ALL OF YOUR BITCOINS</b>!") + | ||||
"<br><br>" + | "<br><br>" + | ||||
tr("Are you sure you wish to encrypt your wallet?"), | tr("Are you sure you wish to encrypt your wallet?"), | ||||
QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel); | QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel); | ||||
if (retval == QMessageBox::Yes) { | if (retval == QMessageBox::Yes) { | ||||
if (newpass1 == newpass2) { | if (newpass1 == newpass2) { | ||||
QString encryption_reminder = | |||||
tr("Remember that encrypting your wallet cannot fully " | |||||
"protect your bitcoins from being stolen by malware " | |||||
"infecting your computer."); | |||||
if (m_passphrase_out) { | |||||
m_passphrase_out->assign(newpass1); | |||||
QMessageBox::warning( | |||||
this, tr("Wallet to be encrypted"), | |||||
"<qt>" + | |||||
tr("Your wallet is about to be encrypted. ") + | |||||
encryption_reminder + "</b></qt>"); | |||||
} else { | |||||
assert(model != nullptr); | |||||
if (model->setWalletEncrypted(true, newpass1)) { | if (model->setWalletEncrypted(true, newpass1)) { | ||||
QMessageBox::warning( | QMessageBox::warning( | ||||
this, tr("Wallet encrypted"), | this, tr("Wallet encrypted"), | ||||
"<qt>" + | "<qt>" + tr("Your wallet is now encrypted. ") + | ||||
tr("Your wallet is now encrypted. " | encryption_reminder + "<br><br><b>" + | ||||
"Remember that encrypting your wallet " | tr("IMPORTANT: Any previous backups you " | ||||
"cannot fully protect your bitcoins from " | "have made of your wallet file should " | ||||
"being stolen by malware infecting your " | "be replaced with the newly generated, " | ||||
"computer.") + | "encrypted wallet file. For security " | ||||
"<br><br><b>" + | "reasons, previous backups of the " | ||||
tr("IMPORTANT: Any previous backups you have " | "unencrypted wallet file will become " | ||||
"made of your wallet file should be " | |||||
"replaced with the newly generated, " | |||||
"encrypted wallet file. " | |||||
"For security reasons, previous backups of " | |||||
"the unencrypted wallet file will become " | |||||
"useless as soon as you start using the " | "useless as soon as you start using the " | ||||
"new, encrypted wallet.") + | "new, encrypted wallet.") + | ||||
"</b></qt>"); | "</b></qt>"); | ||||
} else { | } else { | ||||
QMessageBox::critical( | QMessageBox::critical( | ||||
this, tr("Wallet encryption failed"), | this, tr("Wallet encryption failed"), | ||||
tr("Wallet encryption failed due to an internal " | tr("Wallet encryption failed due to an " | ||||
"error. Your wallet was not encrypted.")); | "internal error. Your wallet was not " | ||||
"encrypted.")); | |||||
} | |||||
} | } | ||||
QDialog::accept(); // Success | QDialog::accept(); // Success | ||||
} else { | } else { | ||||
QMessageBox::critical( | QMessageBox::critical( | ||||
this, tr("Wallet encryption failed"), | this, tr("Wallet encryption failed"), | ||||
tr("The supplied passphrases do not match.")); | tr("The supplied passphrases do not match.")); | ||||
} | } | ||||
} else { | } else { | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | void AskPassphraseDialog::toggleShowPassword(bool show) { | ||||
const auto renderingMode = show ? QLineEdit::Normal : QLineEdit::Password; | const auto renderingMode = show ? QLineEdit::Normal : QLineEdit::Password; | ||||
ui->passEdit1->setEchoMode(renderingMode); | ui->passEdit1->setEchoMode(renderingMode); | ||||
ui->passEdit2->setEchoMode(renderingMode); | ui->passEdit2->setEchoMode(renderingMode); | ||||
ui->passEdit3->setEchoMode(renderingMode); | ui->passEdit3->setEchoMode(renderingMode); | ||||
} | } | ||||
bool AskPassphraseDialog::eventFilter(QObject *object, QEvent *event) { | bool AskPassphraseDialog::eventFilter(QObject *object, QEvent *event) { | ||||
/* Detect Caps Lock. | /* Detect Caps Lock. | ||||
* There is no good OS-independent way to check a key state in Qt, but we | * There is no good OS-independent way to check a key state in Qt, but | ||||
* can detect Caps Lock by checking for the following condition: | * we can detect Caps Lock by checking for the following condition: | ||||
* Shift key is down and the result is a lower case character, or | * Shift key is down and the result is a lower case character, or | ||||
* Shift key is not down and the result is an upper case character. | * Shift key is not down and the result is an upper case character. | ||||
*/ | */ | ||||
if (event->type() == QEvent::KeyPress) { | if (event->type() == QEvent::KeyPress) { | ||||
QKeyEvent *ke = static_cast<QKeyEvent *>(event); | QKeyEvent *ke = static_cast<QKeyEvent *>(event); | ||||
QString str = ke->text(); | QString str = ke->text(); | ||||
if (str.length() != 0) { | if (str.length() != 0) { | ||||
const QChar *psz = str.unicode(); | const QChar *psz = str.unicode(); | ||||
Show All 25 Lines |