5 #if defined(HAVE_CONFIG_H)
10 #include <qt/forms/ui_askpassphrasedialog.h>
19 #include <QMessageBox>
20 #include <QPushButton>
26 m_passphrase_out(passphrase_out)
30 ui->passEdit1->setMinimumSize(
ui->passEdit1->sizeHint());
31 ui->passEdit2->setMinimumSize(
ui->passEdit2->sizeHint());
32 ui->passEdit3->setMinimumSize(
ui->passEdit3->sizeHint());
39 ui->passEdit1->installEventFilter(
this);
40 ui->passEdit2->installEventFilter(
this);
41 ui->passEdit3->installEventFilter(
this);
46 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>."));
47 ui->passLabel1->hide();
48 ui->passEdit1->hide();
49 setWindowTitle(tr(
"Encrypt wallet"));
52 ui->warningLabel->setText(tr(
"This operation needs your wallet 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(
"Enter the old passphrase and new passphrase for the wallet."));
94 oldpass.assign(
ui->passEdit1->text().toStdString().c_str());
95 newpass1.assign(
ui->passEdit2->text().toStdString().c_str());
96 newpass2.assign(
ui->passEdit3->text().toStdString().c_str());
103 if(newpass1.empty() || newpass2.empty())
108 QMessageBox::StandardButton retval = QMessageBox::question(
this, tr(
"Confirm wallet encryption"),
109 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?"),
110 QMessageBox::Yes|QMessageBox::Cancel,
111 QMessageBox::Cancel);
112 if(retval == QMessageBox::Yes)
114 if(newpass1 == newpass2)
116 QString encryption_reminder = tr(
"Remember that encrypting your wallet cannot fully protect "
117 "your bitcoins from being stolen by malware infecting your computer.");
120 QMessageBox::warning(
this, tr(
"Wallet to be encrypted"),
122 tr(
"Your wallet is about to be encrypted. ") + encryption_reminder +
127 QMessageBox::warning(
this, tr(
"Wallet encrypted"),
129 tr(
"Your wallet is now encrypted. ") + encryption_reminder +
131 tr(
"IMPORTANT: Any previous backups you have made of your wallet file "
132 "should be replaced with the newly generated, encrypted wallet file. "
133 "For security reasons, previous backups of the unencrypted wallet file "
134 "will become useless as soon as you start using the new, encrypted wallet.") +
137 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
138 tr(
"Wallet encryption failed due to an internal error. Your wallet was not encrypted."));
145 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
146 tr(
"The supplied passphrases do not match."));
157 QMessageBox::critical(
this, tr(
"Wallet unlock failed"),
158 tr(
"The passphrase entered for the wallet decryption was incorrect."));
162 }
catch (
const std::runtime_error& e) {
163 QMessageBox::critical(
this, tr(
"Wallet unlock failed"), e.what());
167 if(newpass1 == newpass2)
171 QMessageBox::information(
this, tr(
"Wallet encrypted"),
172 tr(
"Wallet passphrase was successfully changed."));
177 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
178 tr(
"The passphrase entered for the wallet decryption was incorrect."));
183 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
184 tr(
"The supplied passphrases do not match."));
193 bool acceptable =
false;
197 acceptable = !
ui->passEdit2->text().isEmpty() && !
ui->passEdit3->text().isEmpty();
200 acceptable = !
ui->passEdit1->text().isEmpty();
203 acceptable = !
ui->passEdit1->text().isEmpty() && !
ui->passEdit2->text().isEmpty() && !
ui->passEdit3->text().isEmpty();
206 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(acceptable);
212 if (
event->type() == QEvent::KeyPress) {
213 QKeyEvent *ke =
static_cast<QKeyEvent *
>(
event);
214 if (ke->key() == Qt::Key_CapsLock) {
218 ui->capsLabel->setText(tr(
"Warning: The Caps Lock key is on!"));
220 ui->capsLabel->clear();
223 return QWidget::event(
event);
228 ui->toggleShowPasswordButton->setDown(show);
229 const auto mode = show ? QLineEdit::Normal : QLineEdit::Password;
230 ui->passEdit1->setEchoMode(
mode);
231 ui->passEdit2->setEchoMode(
mode);
232 ui->passEdit3->setEchoMode(
mode);
243 if (
event->type() == QEvent::KeyPress) {
244 QKeyEvent *ke =
static_cast<QKeyEvent *
>(
event);
245 QString str = ke->text();
246 if (str.length() != 0) {
247 const QChar *psz = str.unicode();
248 bool fShift = (ke->modifiers() & Qt::ShiftModifier) != 0;
249 if ((fShift && *psz >=
'a' && *psz <=
'z') || (!fShift && *psz >=
'A' && *psz <=
'Z')) {
251 ui->capsLabel->setText(tr(
"Warning: The Caps Lock key is on!"));
252 }
else if (psz->isLetter()) {
254 ui->capsLabel->clear();
258 return QDialog::eventFilter(
object,
event);
264 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
Utility functions used by the Bitcoin Qt UI.
void handleCloseWindowShortcut(QWidget *w)
constexpr auto dialog_flags
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString