5 #if defined(HAVE_CONFIG_H) 10 #include <qt/forms/ui_askpassphrasedialog.h> 18 #include <QMessageBox> 19 #include <QPushButton> 30 ui->passEdit1->setMinimumSize(
ui->passEdit1->sizeHint());
31 ui->passEdit2->setMinimumSize(
ui->passEdit2->sizeHint());
32 ui->passEdit3->setMinimumSize(
ui->passEdit3->sizeHint());
34 ui->passEdit1->setMaxLength(MAX_PASSPHRASE_SIZE);
35 ui->passEdit2->setMaxLength(MAX_PASSPHRASE_SIZE);
36 ui->passEdit3->setMaxLength(MAX_PASSPHRASE_SIZE);
39 ui->passEdit1->installEventFilter(
this);
40 ui->passEdit2->installEventFilter(
this);
41 ui->passEdit3->installEventFilter(
this);
46 ui->warningLabel->setText(tr(
"Enter the new passphrase to 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 ui->warningLabel->setText(tr(
"This operation needs your wallet 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(
"Enter the old passphrase and new passphrase to the wallet."));
95 oldpass.reserve(MAX_PASSPHRASE_SIZE);
96 newpass1.reserve(MAX_PASSPHRASE_SIZE);
97 newpass2.reserve(MAX_PASSPHRASE_SIZE);
100 oldpass.assign(
ui->passEdit1->text().toStdString().c_str());
101 newpass1.assign(
ui->passEdit2->text().toStdString().c_str());
102 newpass2.assign(
ui->passEdit3->text().toStdString().c_str());
109 if(newpass1.empty() || newpass2.empty())
114 QMessageBox::StandardButton retval = QMessageBox::question(
this, tr(
"Confirm wallet encryption"),
115 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?"),
116 QMessageBox::Yes|QMessageBox::Cancel,
117 QMessageBox::Cancel);
118 if(retval == QMessageBox::Yes)
120 if(newpass1 == newpass2)
124 QMessageBox::warning(
this, tr(
"Wallet encrypted"),
126 tr(
"Your wallet is now encrypted. " 127 "Remember that encrypting your wallet cannot fully protect " 128 "your bitcoins from being stolen by malware infecting your computer.") +
130 tr(
"IMPORTANT: Any previous backups you have made of your wallet file " 131 "should be replaced with the newly generated, encrypted wallet file. " 132 "For security reasons, previous backups of the unencrypted wallet file " 133 "will become useless as soon as you start using the new, encrypted wallet.") +
138 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
139 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."));
168 QMessageBox::critical(
this, tr(
"Wallet decryption failed"),
169 tr(
"The passphrase entered for the wallet decryption was incorrect."));
177 if(newpass1 == newpass2)
181 QMessageBox::information(
this, tr(
"Wallet encrypted"),
182 tr(
"Wallet passphrase was successfully changed."));
187 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
188 tr(
"The passphrase entered for the wallet decryption was incorrect."));
193 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
194 tr(
"The supplied passphrases do not match."));
203 bool acceptable =
false;
207 acceptable = !
ui->passEdit2->text().isEmpty() && !
ui->passEdit3->text().isEmpty();
211 acceptable = !
ui->passEdit1->text().isEmpty();
214 acceptable = !
ui->passEdit1->text().isEmpty() && !
ui->passEdit2->text().isEmpty() && !
ui->passEdit3->text().isEmpty();
217 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(acceptable);
223 if (
event->type() == QEvent::KeyPress) {
224 QKeyEvent *ke =
static_cast<QKeyEvent *
>(
event);
225 if (ke->key() == Qt::Key_CapsLock) {
229 ui->capsLabel->setText(tr(
"Warning: The Caps Lock key is on!"));
231 ui->capsLabel->clear();
234 return QWidget::event(
event);
239 ui->toggleShowPasswordButton->setDown(show);
240 const auto mode = show ? QLineEdit::Normal : QLineEdit::Password;
241 ui->passEdit1->setEchoMode(
mode);
242 ui->passEdit2->setEchoMode(
mode);
243 ui->passEdit3->setEchoMode(
mode);
254 if (
event->type() == QEvent::KeyPress) {
255 QKeyEvent *ke =
static_cast<QKeyEvent *
>(
event);
256 QString str = ke->text();
257 if (str.length() != 0) {
258 const QChar *psz = str.unicode();
259 bool fShift = (ke->modifiers() & Qt::ShiftModifier) != 0;
260 if ((fShift && *psz >=
'a' && *psz <=
'z') || (!fShift && *psz >=
'A' && *psz <=
'Z')) {
262 ui->capsLabel->setText(tr(
"Warning: The Caps Lock key is on!"));
263 }
else if (psz->isLetter()) {
265 ui->capsLabel->clear();
269 return QDialog::eventFilter(
object,
event);
272 static void SecureClearQLineEdit(QLineEdit* edit)
275 edit->setText(QString(
" ").repeated(edit->text().size()));
281 SecureClearQLineEdit(
ui->passEdit1);
282 SecureClearQLineEdit(
ui->passEdit2);
283 SecureClearQLineEdit(
ui->passEdit3);
bool event(QEvent *event)
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Ask passphrase twice and encrypt.
void toggleShowPassword(bool)
Ask passphrase and unlock.
Ui::AskPassphraseDialog * ui
void secureClearPassFields()
bool changePassphrase(const SecureString &oldPass, const SecureString &newPass)
AddressTableModel * parent
AskPassphraseDialog(Mode mode, QWidget *parent)
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString())
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.
bool eventFilter(QObject *object, QEvent *event)
Ask old passphrase + new passphrase twice.
void setModel(WalletModel *model)