5#if defined(HAVE_CONFIG_H)
6#include <config/bitcoin-config.h>
10#include <qt/forms/ui_askpassphrasedialog.h>
24 model(nullptr), fCapsLock(false), m_passphrase_out(passphrase_out) {
27 ui->passEdit1->setMinimumSize(
ui->passEdit1->sizeHint());
28 ui->passEdit2->setMinimumSize(
ui->passEdit2->sizeHint());
29 ui->passEdit3->setMinimumSize(
ui->passEdit3->sizeHint());
36 ui->passEdit1->installEventFilter(
this);
37 ui->passEdit2->installEventFilter(
this);
38 ui->passEdit3->installEventFilter(
this);
42 ui->warningLabel->setText(
43 tr(
"Enter the new passphrase for the wallet.<br/>Please use a "
44 "passphrase of <b>ten or more random characters</b>, or "
45 "<b>eight or more words</b>."));
46 ui->passLabel1->hide();
47 ui->passEdit1->hide();
48 setWindowTitle(tr(
"Encrypt wallet"));
51 ui->warningLabel->setText(tr(
"This operation needs your wallet "
52 "passphrase to unlock the wallet."));
53 ui->passLabel2->hide();
54 ui->passEdit2->hide();
55 ui->passLabel3->hide();
56 ui->passEdit3->hide();
57 setWindowTitle(tr(
"Unlock wallet"));
60 setWindowTitle(tr(
"Change passphrase"));
61 ui->warningLabel->setText(tr(
62 "Enter the old passphrase and new passphrase for the wallet."));
66 connect(
ui->toggleShowPasswordButton, &QPushButton::toggled,
this,
68 connect(
ui->passEdit1, &QLineEdit::textChanged,
this,
70 connect(
ui->passEdit2, &QLineEdit::textChanged,
this,
72 connect(
ui->passEdit3, &QLineEdit::textChanged,
this,
98 oldpass.assign(
ui->passEdit1->text().toStdString().c_str());
99 newpass1.assign(
ui->passEdit2->text().toStdString().c_str());
100 newpass2.assign(
ui->passEdit3->text().toStdString().c_str());
106 if (newpass1.empty() || newpass2.empty()) {
110 QMessageBox::StandardButton retval = QMessageBox::question(
111 this, tr(
"Confirm wallet encryption"),
112 tr(
"Warning: If you encrypt your wallet and lose your "
113 "passphrase, you will <b>LOSE ALL OF YOUR BITCOINS</b>!") +
115 tr(
"Are you sure you wish to encrypt your wallet?"),
116 QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel);
117 if (retval == QMessageBox::Yes) {
118 if (newpass1 == newpass2) {
119 QString encryption_reminder =
120 tr(
"Remember that encrypting your wallet cannot fully "
121 "protect your bitcoins from being stolen by malware "
122 "infecting your computer.");
125 QMessageBox::warning(
126 this, tr(
"Wallet to be encrypted"),
128 tr(
"Your wallet is about to be encrypted. ") +
129 encryption_reminder +
"</b></qt>");
133 QMessageBox::warning(
134 this, tr(
"Wallet encrypted"),
135 "<qt>" + tr(
"Your wallet is now encrypted. ") +
136 encryption_reminder +
"<br><br><b>" +
137 tr(
"IMPORTANT: Any previous backups you "
138 "have made of your wallet file should "
139 "be replaced with the newly generated, "
140 "encrypted wallet file. For security "
141 "reasons, previous backups of the "
142 "unencrypted wallet file will become "
143 "useless as soon as you start using the "
144 "new, encrypted wallet.") +
147 QMessageBox::critical(
148 this, tr(
"Wallet encryption failed"),
149 tr(
"Wallet encryption failed due to an "
150 "internal error. Your wallet was not "
156 QMessageBox::critical(
157 this, tr(
"Wallet encryption failed"),
158 tr(
"The supplied passphrases do not match."));
167 QMessageBox::critical(
168 this, tr(
"Wallet unlock failed"),
169 tr(
"The passphrase entered for the wallet decryption "
175 }
catch (
const std::runtime_error &e) {
176 QMessageBox::critical(
this, tr(
"Wallet unlock failed"),
181 if (newpass1 == newpass2) {
183 QMessageBox::information(
184 this, tr(
"Wallet encrypted"),
185 tr(
"Wallet passphrase was successfully changed."));
188 QMessageBox::critical(
189 this, tr(
"Wallet encryption failed"),
190 tr(
"The passphrase entered for the wallet decryption "
194 QMessageBox::critical(
195 this, tr(
"Wallet encryption failed"),
196 tr(
"The supplied passphrases do not match."));
204 bool acceptable =
false;
207 acceptable = !
ui->passEdit2->text().isEmpty() &&
208 !
ui->passEdit3->text().isEmpty();
211 acceptable = !
ui->passEdit1->text().isEmpty();
214 acceptable = !
ui->passEdit1->text().isEmpty() &&
215 !
ui->passEdit2->text().isEmpty() &&
216 !
ui->passEdit3->text().isEmpty();
219 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(acceptable);
224 if (
event->type() == QEvent::KeyPress) {
225 QKeyEvent *ke =
static_cast<QKeyEvent *
>(
event);
226 if (ke->key() == Qt::Key_CapsLock) {
230 ui->capsLabel->setText(tr(
"Warning: The Caps Lock key is on!"));
232 ui->capsLabel->clear();
235 return QWidget::event(
event);
239 ui->toggleShowPasswordButton->setDown(show);
240 const auto renderingMode = show ? QLineEdit::Normal : QLineEdit::Password;
241 ui->passEdit1->setEchoMode(renderingMode);
242 ui->passEdit2->setEchoMode(renderingMode);
243 ui->passEdit3->setEchoMode(renderingMode);
253 if (
event->type() == QEvent::KeyPress) {
254 QKeyEvent *ke =
static_cast<QKeyEvent *
>(
event);
255 QString str = ke->text();
256 if (str.length() != 0) {
257 const QChar *psz = str.unicode();
258 bool fShift = (ke->modifiers() & Qt::ShiftModifier) != 0;
259 if ((fShift && *psz >=
'a' && *psz <=
'z') ||
260 (!fShift && *psz >=
'A' && *psz <=
'Z')) {
262 ui->capsLabel->setText(tr(
"Warning: The Caps Lock key is on!"));
263 }
else if (psz->isLetter()) {
265 ui->capsLabel->clear();
269 return QDialog::eventFilter(
object,
event);
274 edit->setText(QString(
" ").repeated(edit->text().size()));
static void SecureClearQLineEdit(QLineEdit *edit)
Multifunctional dialog to ask for passphrases.
void secureClearPassFields()
SecureString * m_passphrase_out
AskPassphraseDialog(Mode mode, QWidget *parent, SecureString *passphrase_out=nullptr)
void toggleShowPassword(bool)
void setModel(WalletModel *model)
bool eventFilter(QObject *object, QEvent *event) override
bool event(QEvent *event) override
@ Unlock
Ask passphrase and unlock.
@ Encrypt
Ask passphrase twice and encrypt.
@ ChangePass
Ask old passphrase + new passphrase twice.
Ui::AskPassphraseDialog * ui
Interface to Bitcoin wallet from Qt view code.
bool setWalletEncrypted(const SecureString &passphrase)
bool changePassphrase(const SecureString &oldPass, const SecureString &newPass)
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString())
static const int MAX_PASSPHRASE_SIZE
void handleCloseWindowShortcut(QWidget *w)
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString