7 #if defined(HAVE_CONFIG_H)
12 #include "ui_askpassphrasedialog.h"
21 #include <QGraphicsDropShadowEffect>
23 #include <QMessageBox>
24 #include <QPushButton>
33 btnWatch(new QCheckBox())
38 ui->left->setProperty(
"cssClass",
"container-dialog");
40 ui->labelTitle->setText(
"Change passphrase");
41 ui->labelTitle->setProperty(
"cssClass",
"text-title-screen");
43 ui->warningLabel->setProperty(
"cssClass",
"text-subtitle");
45 ui->btnEsc->setText(
"");
46 ui->btnEsc->setProperty(
"cssClass",
"ic-close");
48 ui->pushButtonOk->setText(
"OK");
49 ui->pushButtonOk->setProperty(
"cssClass",
"btn-primary");
55 ui->passLabel1->setText(
"Current passphrase");
56 ui->passLabel1->setProperty(
"cssClass",
"text-title");
58 ui->passLabel2->setText(
"New passphrase");
59 ui->passLabel2->setProperty(
"cssClass",
"text-title");
61 ui->passLabel3->setText(
"Repeat passphrase");
62 ui->passLabel3->setProperty(
"cssClass",
"text-title");
65 ui->passWarningLabel->setVisible(
false);
67 ui->passEdit1->setMinimumSize(
ui->passEdit1->sizeHint());
68 ui->passEdit2->setMinimumSize(
ui->passEdit2->sizeHint());
69 ui->passEdit3->setMinimumSize(
ui->passEdit3->sizeHint());
71 ui->passEdit1->setMaxLength(MAX_PASSPHRASE_SIZE);
72 ui->passEdit2->setMaxLength(MAX_PASSPHRASE_SIZE);
73 ui->passEdit3->setMaxLength(MAX_PASSPHRASE_SIZE);
79 ui->passEdit1->installEventFilter(
this);
80 ui->passEdit2->installEventFilter(
this);
81 ui->passEdit3->installEventFilter(
this);
88 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>."));
89 ui->passLabel1->hide();
90 ui->passEdit1->hide();
91 ui->layoutEdit->hide();
92 title = tr(
"Encrypt wallet");
96 ui->warningLabel->setText(tr(
"This operation needs your wallet passphrase to unlock the wallet."));
97 ui->passLabel2->hide();
98 ui->passEdit2->hide();
99 ui->layoutEdit2->hide();
100 ui->passLabel3->hide();
101 ui->passEdit3->hide();
102 title = tr(
"Unlock wallet\nfor staking");
106 ui->warningLabel->setText(tr(
"This operation needs your wallet passphrase to unlock the wallet."));
107 ui->passLabel2->hide();
108 ui->passEdit2->hide();
109 ui->layoutEdit2->hide();
110 ui->passLabel3->hide();
111 ui->passEdit3->hide();
112 title = tr(
"Unlock wallet");
116 ui->warningLabel->setText(tr(
"This operation needs your wallet passphrase to decrypt the wallet."));
117 ui->passLabel2->hide();
118 ui->passEdit2->hide();
119 ui->layoutEdit2->hide();
120 ui->passLabel3->hide();
121 ui->passEdit3->hide();
122 title = tr(
"Decrypt wallet");
126 title = tr(
"Change passphrase");
127 ui->warningLabel->setText(tr(
"Enter the old and new passphrase to the wallet."));
132 ui->labelTitle->setText(title);
140 connect(
ui->btnEsc, &QPushButton::clicked,
this, &AskPassphraseDialog::close);
146 ui->passEdit3->setEchoMode(state == Qt::Checked ? QLineEdit::Normal : QLineEdit::Password );
147 ui->passEdit2->setEchoMode(state== Qt::Checked ? QLineEdit::Normal : QLineEdit::Password );
148 ui->passEdit1->setEchoMode(state == Qt::Checked ? QLineEdit::Normal : QLineEdit::Password );
154 ui->passEdit1->setText(QString(
" ").repeated(
ui->passEdit1->text().size()));
155 ui->passEdit2->setText(QString(
" ").repeated(
ui->passEdit2->text().size()));
156 ui->passEdit3->setText(QString(
" ").repeated(
ui->passEdit3->text().size()));
163 else if (
ui->passEdit1)
ui->passEdit1->setFocus();
171 oldpass.reserve(MAX_PASSPHRASE_SIZE);
172 newpass1.reserve(MAX_PASSPHRASE_SIZE);
173 newpass2.reserve(MAX_PASSPHRASE_SIZE);
176 oldpass.assign(
ui->passEdit1->text().toStdString().c_str());
177 newpass1.assign(
ui->passEdit2->text().toStdString().c_str());
178 newpass2.assign(
ui->passEdit3->text().toStdString().c_str());
182 if (newpass1.empty() || newpass2.empty()) {
188 tr(
"Confirm wallet encryption"),
189 "<b>" + tr(
"WARNING") +
":</b> " + tr(
"If you encrypt your wallet and lose your passphrase, you will") +
190 " <b>" + tr(
"LOSE ALL OF YOUR COINS") +
"</b>!<br><br>" + tr(
"Are you sure you wish to encrypt your wallet?"),
191 tr(
"ENCRYPT"), tr(
"CANCEL")
205 QMessageBox::critical(
this, tr(
"Wallet unlock failed"),
206 tr(
"The passphrase entered for the wallet decryption was incorrect."));
213 QMessageBox::critical(
this, tr(
"Wallet unlock failed"),
214 tr(
"The passphrase entered for the wallet decryption was incorrect."));
221 QMessageBox::critical(
this, tr(
"Wallet decryption failed"),
222 tr(
"The passphrase entered for the wallet decryption was incorrect."));
228 if (newpass1 == newpass2) {
231 openStandardDialog(tr(
"Wallet encrypted"),tr(
"Wallet passphrase was successfully changed."));
234 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
235 tr(
"The passphrase entered for the wallet decryption was incorrect."));
238 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
239 tr(
"The supplied passphrases do not match."));
248 bool acceptable =
false;
251 acceptable = !
ui->passEdit2->text().isEmpty() && !
ui->passEdit3->text().isEmpty() &&
252 ui->passEdit2->text() ==
ui->passEdit3->text();
257 acceptable = !
ui->passEdit1->text().isEmpty();
260 acceptable = !
ui->passEdit2->text().isEmpty() && !
ui->passEdit3->text().isEmpty() &&
261 ui->passEdit2->text() ==
ui->passEdit3->text() &&
262 !
ui->passEdit1->text().isEmpty();
265 ui->pushButtonOk->setEnabled(acceptable);
270 if (
event->type() == QEvent::KeyPress) {
271 QKeyEvent* ke =
static_cast<QKeyEvent*
>(
event);
273 if (ke->key() == Qt::Key_CapsLock) {
280 if ((ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return) &&
ui->pushButtonOk->isEnabled()) {
284 return QDialog::event(
event);
295 if (
event->type() == QEvent::KeyPress) {
296 QKeyEvent* ke =
static_cast<QKeyEvent*
>(
event);
297 QString str = ke->text();
298 if (str.length() != 0) {
299 const QChar* psz = str.unicode();
300 bool fShift = (ke->modifiers() & Qt::ShiftModifier) != 0;
301 if ((fShift && *psz >=
'a' && *psz <=
'z') || (!fShift && *psz >=
'A' && *psz <=
'Z')) {
303 }
else if (psz->isLetter()) {
310 return QDialog::eventFilter(
object,
event);
317 confirmDialog->
setText(title, body, okBtn, cancelBtn);
318 confirmDialog->adjustSize();
320 bool ret = confirmDialog->
isOk;
321 confirmDialog->deleteLater();
328 bool validPassphrases =
false;
329 validPassphrases =
ui->passEdit2->text() ==
ui->passEdit3->text();
330 QString warningStr =
"";
331 if (
fCapsLock || !validPassphrases) warningStr += tr(
"WARNING:") +
"<br>";
332 if (
fCapsLock) warningStr +=
"* " + tr(
"The caps lock key is on!");
333 if (
fCapsLock && !validPassphrases) warningStr +=
"<br>";
334 if (!validPassphrases) warningStr +=
"* " + tr(
"Passphrases do not match!");
336 if (warningStr.isEmpty()) {
337 ui->passWarningLabel->clear();
338 ui->passWarningLabel->setVisible(
false);
340 ui->passWarningLabel->setText(warningStr);
341 ui->passWarningLabel->setVisible(
true);
348 static_cast<PIVXGUI*
>(parentWidget())->showHide(
true);
350 tr(
"Wallet encrypted"),
352 tr(
"Your wallet is now encrypted. "
353 "Remember that encrypting your wallet cannot fully protect "
354 "your PIVs from being stolen by malware infecting your computer.") +
356 tr(
"IMPORTANT: Any previous backups you have made of your wallet file "
357 "should be replaced with the newly generated, encrypted wallet file. "
358 "For security reasons, previous backups of the unencrypted wallet file "
359 "will become useless as soon as you start using the new, encrypted wallet.") +
367 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
368 tr(
"Wallet encryption failed due to an internal error. Your wallet was not encrypted."));
375 QMetaObject::invokeMethod(
this,
"hide", Qt::QueuedConnection);
377 QMetaObject::invokeMethod(
this,
"warningMessage", Qt::QueuedConnection);
379 QMetaObject::invokeMethod(
this,
"errorEncryptingWallet", Qt::QueuedConnection);
389 LogPrintf(
"Error encrypting wallet, %s\n",
error.toStdString());
390 QMetaObject::invokeMethod(
this,
"errorEncryptingWallet", Qt::QueuedConnection);
398 QSize BUTTON_CONTACT_SIZE = QSize(24, 24);
399 btnWatch->setMinimumSize(BUTTON_CONTACT_SIZE);
400 btnWatch->setMaximumSize(BUTTON_CONTACT_SIZE);
Multifunctional dialog to ask for passphrases.
bool openStandardDialog(QString title="", QString body="", QString okBtn="OK", QString cancelBtn="")
bool eventFilter(QObject *object, QEvent *event) override
void onError(QString error, int type) override
void errorEncryptingWallet()
bool event(QEvent *event) override
void run(int type) override
void initWatch(QWidget *parent)
@ ChangePass
Ask old passphrase + new passphrase twice.
@ Encrypt
Ask passphrase twice and encrypt.
@ UnlockAnonymize
Ask passphrase and unlock only for anonymization.
@ Decrypt
Ask passphrase and decrypt wallet.
@ Unlock
Ask passphrase and unlock.
AskPassphraseDialog(Mode mode, QWidget *parent, WalletModel *model, Context context)
SecureString newpassCache
Ui::AskPassphraseDialog * ui
void showEvent(QShowEvent *event) override
void updateWarningsLabel()
void setText(const QString &title="", const QString &message="", const QString &okBtnText="", const QString &cancelBtnText="")
void execute(Runnable *runnable, int type, std::unique_ptr< WalletModel::UnlockContext > pctx=nullptr)
Interface to PIVX wallet from Qt view code.
bool setWalletEncrypted(bool encrypted, const SecureString &passphrase)
bool changePassphrase(const SecureString &oldPass, const SecureString &newPass)
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString(), bool stakingOnly=false)
QString loadStyleSheet()
Load global CSS theme.
bool openDialogWithOpaqueBackgroundFullScreen(QDialog *widget, PIVXGUI *gui)
void initCssEditLine(QLineEdit *edit, bool isDialog)
bool openDialogWithOpaqueBackground(QDialog *widget, PIVXGUI *gui, double posX)
void setShadow(QWidget *edit)
void setCssProperty(std::initializer_list< QWidget * > args, const QString &value)
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
bool error(const char *fmt, const Args &... args)