6 #include <qt/forms/ui_askpassphrasedialog.h>
15 #include <QMessageBox>
16 #include <QPushButton>
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"));
48 ui->warningLabel->setText(tr(
"This operation needs your wallet passphrase to unlock the wallet."));
49 ui->passLabel2->hide();
50 ui->passEdit2->hide();
51 ui->passLabel3->hide();
52 ui->passEdit3->hide();
53 setWindowTitle(tr(
"Unlock wallet"));
56 setWindowTitle(tr(
"Change passphrase"));
57 ui->warningLabel->setText(tr(
"Enter the old passphrase and new passphrase for the wallet."));
89 oldpass.assign(std::string_view{
ui->passEdit1->text().toStdString()});
90 newpass1.assign(std::string_view{
ui->passEdit2->text().toStdString()});
91 newpass2.assign(std::string_view{
ui->passEdit3->text().toStdString()});
98 if(newpass1.empty() || newpass2.empty())
103 QMessageBox::StandardButton retval = QMessageBox::question(
this, tr(
"Confirm wallet encryption"),
104 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?"),
105 QMessageBox::Yes|QMessageBox::Cancel,
106 QMessageBox::Cancel);
107 if(retval == QMessageBox::Yes)
109 if(newpass1 == newpass2)
111 QString encryption_reminder = tr(
"Remember that encrypting your wallet cannot fully protect "
112 "your bitcoins from being stolen by malware infecting your computer.");
115 QMessageBox::warning(
this, tr(
"Wallet to be encrypted"),
117 tr(
"Your wallet is about to be encrypted. ") + encryption_reminder +
122 QMessageBox::warning(
this, tr(
"Wallet encrypted"),
124 tr(
"Your wallet is now encrypted. ") + encryption_reminder +
126 tr(
"IMPORTANT: Any previous backups you have made of your wallet file "
127 "should be replaced with the newly generated, encrypted wallet file. "
128 "For security reasons, previous backups of the unencrypted wallet file "
129 "will become useless as soon as you start using the new, encrypted wallet.") +
132 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
133 tr(
"Wallet encryption failed due to an internal error. Your wallet was not encrypted."));
140 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
141 tr(
"The supplied passphrases do not match."));
153 if (oldpass.find(
'\0') == std::string::npos) {
154 QMessageBox::critical(
this, tr(
"Wallet unlock failed"),
155 tr(
"The passphrase entered for the wallet decryption was incorrect."));
157 QMessageBox::critical(
this, tr(
"Wallet unlock failed"),
158 tr(
"The passphrase entered for the wallet decryption is incorrect. "
159 "It contains a null character (ie - a zero byte). "
160 "If the passphrase was set with a version of this software prior to 25.0, "
161 "please try again with only the characters up to — but not including — "
162 "the first null character. If this is successful, please set a new "
163 "passphrase to avoid this issue in the future."));
171 }
catch (
const std::runtime_error& e) {
172 QMessageBox::critical(
this, tr(
"Wallet unlock failed"), e.what());
176 if(newpass1 == newpass2)
180 QMessageBox::information(
this, tr(
"Wallet encrypted"),
181 tr(
"Wallet passphrase was successfully changed."));
187 if (oldpass.find(
'\0') == std::string::npos) {
188 QMessageBox::critical(
this, tr(
"Passphrase change failed"),
189 tr(
"The passphrase entered for the wallet decryption was incorrect."));
191 QMessageBox::critical(
this, tr(
"Passphrase change failed"),
192 tr(
"The old passphrase entered for the wallet decryption is incorrect. "
193 "It contains a null character (ie - a zero byte). "
194 "If the passphrase was set with a version of this software prior to 25.0, "
195 "please try again with only the characters up to — but not including — "
196 "the first null character."));
202 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
203 tr(
"The supplied passphrases do not match."));
212 bool acceptable =
false;
216 acceptable = !
ui->passEdit2->text().isEmpty() && !
ui->passEdit3->text().isEmpty();
219 acceptable = !
ui->passEdit1->text().isEmpty();
222 acceptable = !
ui->passEdit1->text().isEmpty() && !
ui->passEdit2->text().isEmpty() && !
ui->passEdit3->text().isEmpty();
225 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(acceptable);
231 if (
event->type() == QEvent::KeyPress) {
232 QKeyEvent *ke =
static_cast<QKeyEvent *
>(
event);
233 if (ke->key() == Qt::Key_CapsLock) {
237 ui->capsLabel->setText(tr(
"Warning: The Caps Lock key is on!"));
239 ui->capsLabel->clear();
242 return QWidget::event(
event);
247 ui->toggleShowPasswordButton->setDown(show);
248 const auto mode = show ? QLineEdit::Normal : QLineEdit::Password;
249 ui->passEdit1->setEchoMode(
mode);
250 ui->passEdit2->setEchoMode(
mode);
251 ui->passEdit3->setEchoMode(
mode);
262 if (
event->type() == QEvent::KeyPress) {
263 QKeyEvent *ke =
static_cast<QKeyEvent *
>(
event);
264 QString str = ke->text();
265 if (str.length() != 0) {
266 const QChar *psz = str.unicode();
267 bool fShift = (ke->modifiers() & Qt::ShiftModifier) != 0;
268 if ((fShift && *psz >=
'a' && *psz <=
'z') || (!fShift && *psz >=
'A' && *psz <=
'Z')) {
270 ui->capsLabel->setText(tr(
"Warning: The Caps Lock key is on!"));
271 }
else if (psz->isLetter()) {
273 ui->capsLabel->clear();
277 return QDialog::eventFilter(
object,
event);
283 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