5 #if defined(HAVE_CONFIG_H) 10 #include <qt/forms/ui_askpassphrasedialog.h> 19 #include <QMessageBox> 20 #include <QPushButton> 28 m_passphrase_out(passphrase_out)
32 ui->passEdit1->setMinimumSize(
ui->passEdit1->sizeHint());
33 ui->passEdit2->setMinimumSize(
ui->passEdit2->sizeHint());
34 ui->passEdit3->setMinimumSize(
ui->passEdit3->sizeHint());
41 ui->passEdit1->installEventFilter(
this);
42 ui->passEdit2->installEventFilter(
this);
43 ui->passEdit3->installEventFilter(
this);
48 ui->warningLabel->setText(tr(
"Enter the new passphrase for the wallet.<br/>Please use a passphrase of <b>ten or more random characters</b>, or <b>eight or more words</b>."));
49 ui->passLabel1->hide();
50 ui->passEdit1->hide();
51 setWindowTitle(tr(
"Encrypt wallet"));
54 ui->warningLabel->setText(tr(
"This operation needs your wallet passphrase to unlock the wallet."));
55 ui->passLabel2->hide();
56 ui->passEdit2->hide();
57 ui->passLabel3->hide();
58 ui->passEdit3->hide();
59 setWindowTitle(tr(
"Unlock wallet"));
62 setWindowTitle(tr(
"Change passphrase"));
63 ui->warningLabel->setText(tr(
"Enter the old passphrase and new passphrase for the wallet."));
96 oldpass.assign(
ui->passEdit1->text().toStdString().c_str());
97 newpass1.assign(
ui->passEdit2->text().toStdString().c_str());
98 newpass2.assign(
ui->passEdit3->text().toStdString().c_str());
105 if(newpass1.empty() || newpass2.empty())
110 QMessageBox::StandardButton retval = QMessageBox::question(
this, tr(
"Confirm wallet encryption"),
111 tr(
"Warning: If you encrypt your wallet and lose your passphrase, you will <b>LOSE ALL OF YOUR BITCOINS</b>!") +
"<br><br>" + tr(
"Are you sure you wish to encrypt your wallet?"),
112 QMessageBox::Yes|QMessageBox::Cancel,
113 QMessageBox::Cancel);
114 if(retval == QMessageBox::Yes)
116 if(newpass1 == newpass2)
118 QString encryption_reminder = tr(
"Remember that encrypting your wallet cannot fully protect " 119 "your bitcoins from being stolen by malware infecting your computer.");
122 QMessageBox::warning(
this, tr(
"Wallet to be encrypted"),
124 tr(
"Your wallet is about to be encrypted. ") + encryption_reminder +
129 QMessageBox::warning(
this, tr(
"Wallet encrypted"),
131 tr(
"Your wallet is now encrypted. ") + encryption_reminder +
133 tr(
"IMPORTANT: Any previous backups you have made of your wallet file " 134 "should be replaced with the newly generated, encrypted wallet file. " 135 "For security reasons, previous backups of the unencrypted wallet file " 136 "will become useless as soon as you start using the new, encrypted wallet.") +
139 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
140 tr(
"Wallet encryption failed due to an internal error. Your wallet was not encrypted."));
147 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
148 tr(
"The supplied passphrases do not match."));
159 QMessageBox::critical(
this, tr(
"Wallet unlock failed"),
160 tr(
"The passphrase entered for the wallet decryption was incorrect."));
164 }
catch (
const std::runtime_error& e) {
165 QMessageBox::critical(
this, tr(
"Wallet unlock failed"), e.what());
169 if(newpass1 == newpass2)
173 QMessageBox::information(
this, tr(
"Wallet encrypted"),
174 tr(
"Wallet passphrase was successfully changed."));
179 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
180 tr(
"The passphrase entered for the wallet decryption was incorrect."));
185 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
186 tr(
"The supplied passphrases do not match."));
195 bool acceptable =
false;
199 acceptable = !
ui->passEdit2->text().isEmpty() && !
ui->passEdit3->text().isEmpty();
202 acceptable = !
ui->passEdit1->text().isEmpty();
205 acceptable = !
ui->passEdit1->text().isEmpty() && !
ui->passEdit2->text().isEmpty() && !
ui->passEdit3->text().isEmpty();
208 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(acceptable);
214 if (event->type() == QEvent::KeyPress) {
215 QKeyEvent *ke =
static_cast<QKeyEvent *
>(
event);
216 if (ke->key() == Qt::Key_CapsLock) {
220 ui->capsLabel->setText(tr(
"Warning: The Caps Lock key is on!"));
222 ui->capsLabel->clear();
225 return QWidget::event(event);
230 ui->toggleShowPasswordButton->setDown(show);
231 const auto mode = show ? QLineEdit::Normal : QLineEdit::Password;
232 ui->passEdit1->setEchoMode(
mode);
233 ui->passEdit2->setEchoMode(
mode);
234 ui->passEdit3->setEchoMode(
mode);
245 if (event->type() == QEvent::KeyPress) {
246 QKeyEvent *ke =
static_cast<QKeyEvent *
>(
event);
247 QString str = ke->text();
248 if (str.length() != 0) {
249 const QChar *psz = str.unicode();
250 bool fShift = (ke->modifiers() & Qt::ShiftModifier) != 0;
251 if ((fShift && *psz >=
'a' && *psz <=
'z') || (!fShift && *psz >=
'A' && *psz <=
'Z')) {
253 ui->capsLabel->setText(tr(
"Warning: The Caps Lock key is on!"));
254 }
else if (psz->isLetter()) {
256 ui->capsLabel->clear();
260 return QDialog::eventFilter(
object, event);
266 edit->setText(QString(
" ").repeated(edit->text().size()));
static const int MAX_PASSPHRASE_SIZE
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Ask passphrase twice and encrypt.
bool event(QEvent *event) override
static void SecureClearQLineEdit(QLineEdit *edit)
void toggleShowPassword(bool)
Ask passphrase and unlock.
Ui::AskPassphraseDialog * ui
void secureClearPassFields()
void handleCloseWindowShortcut(QWidget *w)
bool changePassphrase(const SecureString &oldPass, const SecureString &newPass)
SecureString * m_passphrase_out
AskPassphraseDialog(Mode mode, QWidget *parent, SecureString *passphrase_out=nullptr)
bool setWalletEncrypted(const SecureString &passphrase)
AddressTableModel * parent
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString())
bool eventFilter(QObject *object, QEvent *event) override
Interface to Bitcoin wallet from Qt view code.
Multifunctional dialog to ask for passphrases.
Ask old passphrase + new passphrase twice.
void setModel(WalletModel *model)