5 #if defined(HAVE_CONFIG_H) 6 #include <config/bitcoin-config.h> 10 #include <qt/forms/ui_askpassphrasedialog.h> 17 #include <QMessageBox> 18 #include <QPushButton> 23 model(nullptr), fCapsLock(false), 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);
41 ui->warningLabel->setText(
42 tr(
"Enter the new passphrase for the wallet.<br/>Please use a " 43 "passphrase of <b>ten or more random characters</b>, or " 44 "<b>eight or more words</b>."));
45 ui->passLabel1->hide();
46 ui->passEdit1->hide();
47 setWindowTitle(tr(
"Encrypt wallet"));
50 ui->warningLabel->setText(tr(
"This operation needs your wallet " 51 "passphrase to unlock the wallet."));
52 ui->passLabel2->hide();
53 ui->passEdit2->hide();
54 ui->passLabel3->hide();
55 ui->passEdit3->hide();
56 setWindowTitle(tr(
"Unlock wallet"));
59 ui->warningLabel->setText(tr(
"This operation needs your wallet " 60 "passphrase to decrypt the wallet."));
61 ui->passLabel2->hide();
62 ui->passEdit2->hide();
63 ui->passLabel3->hide();
64 ui->passEdit3->hide();
65 setWindowTitle(tr(
"Decrypt wallet"));
68 setWindowTitle(tr(
"Change passphrase"));
69 ui->warningLabel->setText(tr(
70 "Enter the old passphrase and new passphrase for the wallet."));
74 connect(
ui->toggleShowPasswordButton, &QPushButton::toggled,
this,
76 connect(
ui->passEdit1, &QLineEdit::textChanged,
this,
78 connect(
ui->passEdit2, &QLineEdit::textChanged,
this,
80 connect(
ui->passEdit3, &QLineEdit::textChanged,
this,
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());
112 if (newpass1.empty() || newpass2.empty()) {
116 QMessageBox::StandardButton retval = QMessageBox::question(
117 this, tr(
"Confirm wallet encryption"),
118 tr(
"Warning: If you encrypt your wallet and lose your " 119 "passphrase, you will <b>LOSE ALL OF YOUR BITCOINS</b>!") +
121 tr(
"Are you sure you wish to encrypt your wallet?"),
122 QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel);
123 if (retval == QMessageBox::Yes) {
124 if (newpass1 == newpass2) {
125 QString encryption_reminder =
126 tr(
"Remember that encrypting your wallet cannot fully " 127 "protect your bitcoins from being stolen by malware " 128 "infecting your computer.");
131 QMessageBox::warning(
132 this, tr(
"Wallet to be encrypted"),
134 tr(
"Your wallet is about to be encrypted. ") +
135 encryption_reminder +
"</b></qt>");
137 assert(
model !=
nullptr);
139 QMessageBox::warning(
140 this, tr(
"Wallet encrypted"),
141 "<qt>" + tr(
"Your wallet is now encrypted. ") +
142 encryption_reminder +
"<br><br><b>" +
143 tr(
"IMPORTANT: Any previous backups you " 144 "have made of your wallet file should " 145 "be replaced with the newly generated, " 146 "encrypted wallet file. For security " 147 "reasons, previous backups of the " 148 "unencrypted wallet file will become " 149 "useless as soon as you start using the " 150 "new, encrypted wallet.") +
153 QMessageBox::critical(
154 this, tr(
"Wallet encryption failed"),
155 tr(
"Wallet encryption failed due to an " 156 "internal error. Your wallet was not " 162 QMessageBox::critical(
163 this, tr(
"Wallet encryption failed"),
164 tr(
"The supplied passphrases do not match."));
173 QMessageBox::critical(
174 this, tr(
"Wallet unlock failed"),
175 tr(
"The passphrase entered for the wallet decryption " 181 }
catch (
const std::runtime_error &e) {
182 QMessageBox::critical(
this, tr(
"Wallet unlock failed"),
188 QMessageBox::critical(
this, tr(
"Wallet decryption failed"),
189 tr(
"The passphrase entered for the " 190 "wallet decryption was incorrect."));
196 if (newpass1 == newpass2) {
198 QMessageBox::information(
199 this, tr(
"Wallet encrypted"),
200 tr(
"Wallet passphrase was successfully changed."));
203 QMessageBox::critical(
204 this, tr(
"Wallet encryption failed"),
205 tr(
"The passphrase entered for the wallet decryption " 209 QMessageBox::critical(
210 this, tr(
"Wallet encryption failed"),
211 tr(
"The supplied passphrases do not match."));
219 bool acceptable =
false;
222 acceptable = !
ui->passEdit2->text().isEmpty() &&
223 !
ui->passEdit3->text().isEmpty();
227 acceptable = !
ui->passEdit1->text().isEmpty();
230 acceptable = !
ui->passEdit1->text().isEmpty() &&
231 !
ui->passEdit2->text().isEmpty() &&
232 !
ui->passEdit3->text().isEmpty();
235 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(acceptable);
240 if (event->type() == QEvent::KeyPress) {
241 QKeyEvent *ke =
static_cast<QKeyEvent *
>(
event);
242 if (ke->key() == Qt::Key_CapsLock) {
246 ui->capsLabel->setText(tr(
"Warning: The Caps Lock key is on!"));
248 ui->capsLabel->clear();
251 return QWidget::event(event);
255 ui->toggleShowPasswordButton->setDown(show);
256 const auto renderingMode = show ? QLineEdit::Normal : QLineEdit::Password;
257 ui->passEdit1->setEchoMode(renderingMode);
258 ui->passEdit2->setEchoMode(renderingMode);
259 ui->passEdit3->setEchoMode(renderingMode);
269 if (event->type() == QEvent::KeyPress) {
270 QKeyEvent *ke =
static_cast<QKeyEvent *
>(
event);
271 QString str = ke->text();
272 if (str.length() != 0) {
273 const QChar *psz = str.unicode();
274 bool fShift = (ke->modifiers() & Qt::ShiftModifier) != 0;
275 if ((fShift && *psz >=
'a' && *psz <=
'z') ||
276 (!fShift && *psz >=
'A' && *psz <=
'Z')) {
278 ui->capsLabel->setText(tr(
"Warning: The Caps Lock key is on!"));
279 }
else if (psz->isLetter()) {
281 ui->capsLabel->clear();
285 return QDialog::eventFilter(
object, event);
290 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()
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)