6#include <qt/forms/ui_askpassphrasedialog.h>
22 m_passphrase_out(passphrase_out)
26 ui->passEdit1->setMinimumSize(
ui->passEdit1->sizeHint());
27 ui->passEdit2->setMinimumSize(
ui->passEdit2->sizeHint());
28 ui->passEdit3->setMinimumSize(
ui->passEdit3->sizeHint());
35 ui->passEdit1->installEventFilter(
this);
36 ui->passEdit2->installEventFilter(
this);
37 ui->passEdit3->installEventFilter(
this);
42 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>."));
43 ui->passLabel1->hide();
44 ui->passEdit1->hide();
45 setWindowTitle(tr(
"Encrypt wallet"));
49 ui->warningLabel->setText(tr(
"This operation needs your wallet passphrase to unlock the wallet."));
50 ui->passLabel2->hide();
51 ui->passEdit2->hide();
52 ui->passLabel3->hide();
53 ui->passEdit3->hide();
54 setWindowTitle(tr(
"Unlock wallet"));
57 setWindowTitle(tr(
"Change passphrase"));
58 ui->warningLabel->setText(tr(
"Enter the old passphrase and new passphrase for the wallet."));
90 oldpass.assign(std::string_view{
ui->passEdit1->text().toStdString()});
91 newpass1.assign(std::string_view{
ui->passEdit2->text().toStdString()});
92 newpass2.assign(std::string_view{
ui->passEdit3->text().toStdString()});
99 if(newpass1.empty() || newpass2.empty())
104 QMessageBox msgBoxConfirm(QMessageBox::Question,
105 tr(
"Confirm wallet encryption"),
106 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?"),
107 QMessageBox::Cancel | QMessageBox::Yes,
this);
108 msgBoxConfirm.button(QMessageBox::Yes)->setText(tr(
"Continue"));
109 msgBoxConfirm.button(QMessageBox::Cancel)->setText(tr(
"Back"));
110 msgBoxConfirm.setDefaultButton(QMessageBox::Cancel);
111 QMessageBox::StandardButton retval = (QMessageBox::StandardButton)msgBoxConfirm.exec();
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.");
121 tr(
"Wallet to be encrypted"),
123 tr(
"Your wallet is about to be encrypted. ") + encryption_reminder +
" " +
124 tr(
"Are you sure you wish to encrypt your wallet?") +
126 QMessageBox::Cancel | QMessageBox::Yes,
this);
127 msgBoxWarning.setDefaultButton(QMessageBox::Cancel);
128 QMessageBox::StandardButton retval = (QMessageBox::StandardButton)msgBoxWarning.exec();
129 if (retval == QMessageBox::Cancel) {
136 QMessageBox::warning(
this, tr(
"Wallet encrypted"),
138 tr(
"Your wallet is now encrypted. ") + encryption_reminder +
140 tr(
"IMPORTANT: Any previous backups you have made of your wallet file "
141 "should be replaced with the newly generated, encrypted wallet file. "
142 "For security reasons, previous backups of the unencrypted wallet file "
143 "will become useless as soon as you start using the new, encrypted wallet.") +
146 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
147 tr(
"Wallet encryption failed due to an internal error. Your wallet was not encrypted."));
154 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
155 tr(
"The supplied passphrases do not match."));
163 if (oldpass.find(
'\0') == std::string::npos) {
164 QMessageBox::critical(
this, tr(
"Wallet unlock failed"),
165 tr(
"The passphrase entered for the wallet decryption was incorrect."));
167 QMessageBox::critical(
this, tr(
"Wallet unlock failed"),
168 tr(
"The passphrase entered for the wallet decryption is incorrect. "
169 "It contains a null character (ie - a zero byte). "
170 "If the passphrase was set with a version of this software prior to 25.0, "
171 "please try again with only the characters up to — but not including — "
172 "the first null character. If this is successful, please set a new "
173 "passphrase to avoid this issue in the future."));
181 }
catch (
const std::runtime_error& e) {
182 QMessageBox::critical(
this, tr(
"Wallet unlock failed"), e.what());
190 if(newpass1 == newpass2)
194 QMessageBox::information(
this, tr(
"Wallet encrypted"),
195 tr(
"Wallet passphrase was successfully changed."));
201 if (oldpass.find(
'\0') == std::string::npos) {
202 QMessageBox::critical(
this, tr(
"Passphrase change failed"),
203 tr(
"The passphrase entered for the wallet decryption was incorrect."));
205 QMessageBox::critical(
this, tr(
"Passphrase change failed"),
206 tr(
"The old passphrase entered for the wallet decryption is incorrect. "
207 "It contains a null character (ie - a zero byte). "
208 "If the passphrase was set with a version of this software prior to 25.0, "
209 "please try again with only the characters up to — but not including — "
210 "the first null character."));
216 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
217 tr(
"The supplied passphrases do not match."));
226 bool acceptable =
false;
230 acceptable = !
ui->passEdit2->text().isEmpty() && !
ui->passEdit3->text().isEmpty();
234 acceptable = !
ui->passEdit1->text().isEmpty();
237 acceptable = !
ui->passEdit1->text().isEmpty() && !
ui->passEdit2->text().isEmpty() && !
ui->passEdit3->text().isEmpty();
240 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(acceptable);
246 if (
event->type() == QEvent::KeyPress) {
247 QKeyEvent *ke =
static_cast<QKeyEvent *
>(
event);
248 if (ke->key() == Qt::Key_CapsLock) {
252 ui->capsLabel->setText(tr(
"Warning: The Caps Lock key is on!"));
254 ui->capsLabel->clear();
257 return QWidget::event(
event);
262 ui->toggleShowPasswordButton->setDown(show);
263 const auto mode = show ? QLineEdit::Normal : QLineEdit::Password;
264 ui->passEdit1->setEchoMode(
mode);
265 ui->passEdit2->setEchoMode(
mode);
266 ui->passEdit3->setEchoMode(
mode);
277 if (
event->type() == QEvent::KeyPress) {
278 QKeyEvent *ke =
static_cast<QKeyEvent *
>(
event);
279 QString str = ke->text();
280 if (str.length() != 0) {
281 const QChar *psz = str.unicode();
282 bool fShift = (ke->modifiers() & Qt::ShiftModifier) != 0;
283 if ((fShift && *psz >=
'a' && *psz <=
'z') || (!fShift && *psz >=
'A' && *psz <=
'Z')) {
285 ui->capsLabel->setText(tr(
"Warning: The Caps Lock key is on!"));
286 }
else if (psz->isLetter()) {
288 ui->capsLabel->clear();
292 return QDialog::eventFilter(
object,
event);
298 edit->setText(QString(
" ").repeated(edit->text().size()));
static void SecureClearQLineEdit(QLineEdit *edit)
#define Assume(val)
Assume is the identity function.
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.
@ UnlockMigration
Ask passphrase for unlocking during migration.
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