6#include <qt/forms/ui_askpassphrasedialog.h>
23 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);
43 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>."));
44 ui->passLabel1->hide();
45 ui->passEdit1->hide();
46 setWindowTitle(tr(
"Encrypt wallet"));
50 ui->warningLabel->setText(tr(
"This operation needs your wallet passphrase to unlock the wallet."));
51 ui->passLabel2->hide();
52 ui->passEdit2->hide();
53 ui->passLabel3->hide();
54 ui->passEdit3->hide();
55 setWindowTitle(tr(
"Unlock wallet"));
58 setWindowTitle(tr(
"Change passphrase"));
59 ui->warningLabel->setText(tr(
"Enter the old passphrase and new passphrase for the wallet."));
91 oldpass.assign(std::string_view{
ui->passEdit1->text().toStdString()});
92 newpass1.assign(std::string_view{
ui->passEdit2->text().toStdString()});
93 newpass2.assign(std::string_view{
ui->passEdit3->text().toStdString()});
100 if(newpass1.empty() || newpass2.empty())
105 QMessageBox msgBoxConfirm(QMessageBox::Question,
106 tr(
"Confirm wallet encryption"),
107 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?"),
108 QMessageBox::Cancel | QMessageBox::Yes,
this);
109 msgBoxConfirm.button(QMessageBox::Yes)->setText(tr(
"Continue"));
110 msgBoxConfirm.button(QMessageBox::Cancel)->setText(tr(
"Back"));
111 msgBoxConfirm.setDefaultButton(QMessageBox::Cancel);
112 QMessageBox::StandardButton retval = (QMessageBox::StandardButton)msgBoxConfirm.exec();
113 if(retval == QMessageBox::Yes)
115 if(newpass1 == newpass2)
117 QString encryption_reminder = tr(
"Remember that encrypting your wallet cannot fully protect "
118 "your bitcoins from being stolen by malware infecting your computer.");
122 tr(
"Wallet to be encrypted"),
124 tr(
"Your wallet is about to be encrypted. ") + encryption_reminder +
" " +
125 tr(
"Are you sure you wish to encrypt your wallet?") +
127 QMessageBox::Cancel | QMessageBox::Yes,
this);
128 msgBoxWarning.setDefaultButton(QMessageBox::Cancel);
129 QMessageBox::StandardButton retval = (QMessageBox::StandardButton)msgBoxWarning.exec();
130 if (retval == QMessageBox::Cancel) {
137 QMessageBox::warning(
this, tr(
"Wallet encrypted"),
139 tr(
"Your wallet is now encrypted. ") + encryption_reminder +
141 tr(
"IMPORTANT: Any previous backups you have made of your wallet file "
142 "should be replaced with the newly generated, encrypted wallet file. "
143 "For security reasons, previous backups of the unencrypted wallet file "
144 "will become useless as soon as you start using the new, encrypted wallet.") +
147 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
148 tr(
"Wallet encryption failed due to an internal error. Your wallet was not encrypted."));
155 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
156 tr(
"The supplied passphrases do not match."));
162 if (
auto unlocked{
model->
wallet().unlock(oldpass)}; !unlocked) {
163 QMessageBox::critical(
this, tr(
"Wallet unlock failed"), QString::fromStdString(unlocked.error().message.translated));
170 }
catch (
const std::runtime_error& e) {
171 QMessageBox::critical(
this, tr(
"Wallet unlock failed"), e.what());
179 if(newpass1 == newpass2)
182 QMessageBox::information(
this, tr(
"Wallet encrypted"),
183 tr(
"Wallet passphrase was successfully changed."));
186 QMessageBox::critical(
this, tr(
"Passphrase change failed"), QString::fromStdString(changed.error().message.translated));
191 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
192 tr(
"The supplied passphrases do not match."));
201 bool acceptable =
false;
205 acceptable = !
ui->passEdit2->text().isEmpty() && !
ui->passEdit3->text().isEmpty();
209 acceptable = !
ui->passEdit1->text().isEmpty();
212 acceptable = !
ui->passEdit1->text().isEmpty() && !
ui->passEdit2->text().isEmpty() && !
ui->passEdit3->text().isEmpty();
215 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(acceptable);
221 if (
event->type() == QEvent::KeyPress) {
222 QKeyEvent *ke =
static_cast<QKeyEvent *
>(
event);
223 if (ke->key() == Qt::Key_CapsLock) {
227 ui->capsLabel->setText(tr(
"Warning: The Caps Lock key is on!"));
229 ui->capsLabel->clear();
232 return QWidget::event(
event);
237 ui->toggleShowPasswordButton->setDown(show);
238 const auto mode = show ? QLineEdit::Normal : QLineEdit::Password;
239 ui->passEdit1->setEchoMode(
mode);
240 ui->passEdit2->setEchoMode(
mode);
241 ui->passEdit3->setEchoMode(
mode);
252 if (
event->type() == QEvent::KeyPress) {
253 QKeyEvent *ke =
static_cast<QKeyEvent *
>(
event);
254 QString str = ke->text();
255 if (str.length() != 0) {
256 const QChar *psz = str.unicode();
257 bool fShift = (ke->modifiers() & Qt::ShiftModifier) != 0;
258 if ((fShift && *psz >=
'a' && *psz <=
'z') || (!fShift && *psz >=
'A' && *psz <=
'Z')) {
260 ui->capsLabel->setText(tr(
"Warning: The Caps Lock key is on!"));
261 }
else if (psz->isLetter()) {
263 ui->capsLabel->clear();
267 return QDialog::eventFilter(
object,
event);
273 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.
util::Expected< void, wallet::WalletError > changePassphrase(const SecureString &oldPass, const SecureString &newPass)
bool setWalletEncrypted(const SecureString &passphrase)
interfaces::Wallet & wallet() const
constexpr 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
is a home for public enum and struct type definitions that are used by internally by wallet code,...