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 ui->warningLabel->setText(tr(
"This operation needs your wallet passphrase to decrypt the wallet."));
63 ui->passLabel2->hide();
64 ui->passEdit2->hide();
65 ui->passLabel3->hide();
66 ui->passEdit3->hide();
67 setWindowTitle(tr(
"Decrypt wallet"));
70 setWindowTitle(tr(
"Change passphrase"));
71 ui->warningLabel->setText(tr(
"Enter the old passphrase and new passphrase for the wallet."));
104 oldpass.assign(
ui->passEdit1->text().toStdString().c_str());
105 newpass1.assign(
ui->passEdit2->text().toStdString().c_str());
106 newpass2.assign(
ui->passEdit3->text().toStdString().c_str());
113 if(newpass1.empty() || newpass2.empty())
118 QMessageBox::StandardButton retval = QMessageBox::question(
this, tr(
"Confirm wallet encryption"),
119 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?"),
120 QMessageBox::Yes|QMessageBox::Cancel,
121 QMessageBox::Cancel);
122 if(retval == QMessageBox::Yes)
124 if(newpass1 == newpass2)
126 QString encryption_reminder = tr(
"Remember that encrypting your wallet cannot fully protect "
127 "your bitcoins from being stolen by malware infecting your computer.");
130 QMessageBox::warning(
this, tr(
"Wallet to be encrypted"),
132 tr(
"Your wallet is about to be encrypted. ") + encryption_reminder +
135 assert(
model !=
nullptr);
138 QMessageBox::warning(
this, tr(
"Wallet encrypted"),
140 tr(
"Your wallet is now encrypted. ") + encryption_reminder +
142 tr(
"IMPORTANT: Any previous backups you have made of your wallet file "
143 "should be replaced with the newly generated, encrypted wallet file. "
144 "For security reasons, previous backups of the unencrypted wallet file "
145 "will become useless as soon as you start using the new, encrypted wallet.") +
150 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
151 tr(
"Wallet encryption failed due to an internal error. Your wallet was not encrypted."));
158 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
159 tr(
"The supplied passphrases do not match."));
170 QMessageBox::critical(
this, tr(
"Wallet unlock failed"),
171 tr(
"The passphrase entered for the wallet decryption was incorrect."));
175 }
catch (
const std::runtime_error& e) {
176 QMessageBox::critical(
this, tr(
"Wallet unlock failed"), e.what());
182 QMessageBox::critical(
this, tr(
"Wallet decryption failed"),
183 tr(
"The passphrase entered for the wallet decryption was incorrect."));
191 if(newpass1 == newpass2)
195 QMessageBox::information(
this, tr(
"Wallet encrypted"),
196 tr(
"Wallet passphrase was successfully changed."));
201 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
202 tr(
"The passphrase entered for the wallet decryption was incorrect."));
207 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
208 tr(
"The supplied passphrases do not match."));
217 bool acceptable =
false;
221 acceptable = !
ui->passEdit2->text().isEmpty() && !
ui->passEdit3->text().isEmpty();
225 acceptable = !
ui->passEdit1->text().isEmpty();
228 acceptable = !
ui->passEdit1->text().isEmpty() && !
ui->passEdit2->text().isEmpty() && !
ui->passEdit3->text().isEmpty();
231 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(acceptable);
237 if (event->type() == QEvent::KeyPress) {
238 QKeyEvent *ke =
static_cast<QKeyEvent *
>(
event);
239 if (ke->key() == Qt::Key_CapsLock) {
243 ui->capsLabel->setText(tr(
"Warning: The Caps Lock key is on!"));
245 ui->capsLabel->clear();
248 return QWidget::event(event);
253 ui->toggleShowPasswordButton->setDown(show);
254 const auto mode = show ? QLineEdit::Normal : QLineEdit::Password;
255 ui->passEdit1->setEchoMode(
mode);
256 ui->passEdit2->setEchoMode(
mode);
257 ui->passEdit3->setEchoMode(
mode);
268 if (event->type() == QEvent::KeyPress) {
269 QKeyEvent *ke =
static_cast<QKeyEvent *
>(
event);
270 QString str = ke->text();
271 if (str.length() != 0) {
272 const QChar *psz = str.unicode();
273 bool fShift = (ke->modifiers() & Qt::ShiftModifier) != 0;
274 if ((fShift && *psz >=
'a' && *psz <=
'z') || (!fShift && *psz >=
'A' && *psz <=
'Z')) {
276 ui->capsLabel->setText(tr(
"Warning: The Caps Lock key is on!"));
277 }
else if (psz->isLetter()) {
279 ui->capsLabel->clear();
283 return QDialog::eventFilter(
object, event);
289 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)
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.
bool setWalletEncrypted(bool encrypted, const SecureString &passphrase)
Ask passphrase and decrypt wallet.
Ask old passphrase + new passphrase twice.
void setModel(WalletModel *model)