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 " | ||||
"being stolen by malware infecting your " | |||||
"computer.") + | |||||
"<br><br><b>" + | |||||
tr("IMPORTANT: Any previous backups you have " | |||||
"made of your wallet file should be " | "made of your wallet file should be " | ||||
"replaced with the newly generated, " | "replaced with the newly generated, " | ||||
"encrypted wallet file. " | "encrypted wallet file. " | ||||
"For security reasons, previous backups of " | "For security reasons, previous backups " | ||||
"the unencrypted wallet file will become " | "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 " | ||||
"internal " | |||||
"error. Your wallet was not encrypted.")); | "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 { | ||||
QDialog::reject(); // Cancelled | QDialog::reject(); // Cancelled | ||||
Show All 20 Lines | switch (mode) { | ||||
case ChangePass: | case ChangePass: | ||||
if (newpass1 == newpass2) { | if (newpass1 == newpass2) { | ||||
if (model->changePassphrase(oldpass, newpass1)) { | if (model->changePassphrase(oldpass, newpass1)) { | ||||
QMessageBox::information( | QMessageBox::information( | ||||
this, tr("Wallet encrypted"), | this, tr("Wallet encrypted"), | ||||
tr("Wallet passphrase was successfully changed.")); | tr("Wallet passphrase was successfully changed.")); | ||||
QDialog::accept(); // Success | QDialog::accept(); // Success | ||||
} else { | } else { | ||||
QMessageBox::critical( | QMessageBox::critical(this, tr("Wallet encryption failed"), | ||||
this, tr("Wallet encryption failed"), | tr("The passphrase entered for " | ||||
tr("The passphrase entered for the wallet decryption " | "the wallet decryption " | ||||
"was incorrect.")); | "was incorrect.")); | ||||
} | } | ||||
} 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.")); | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 41 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 |