9 #include "ui_askpassphrasedialog.h"
17 #include <QMessageBox>
18 #include <QPushButton>
29 ui->passEdit1->setMinimumSize(
ui->passEdit1->sizeHint());
30 ui->passEdit2->setMinimumSize(
ui->passEdit2->sizeHint());
31 ui->passEdit3->setMinimumSize(
ui->passEdit3->sizeHint());
33 ui->passEdit1->setMaxLength(MAX_PASSPHRASE_SIZE);
34 ui->passEdit2->setMaxLength(MAX_PASSPHRASE_SIZE);
35 ui->passEdit3->setMaxLength(MAX_PASSPHRASE_SIZE);
38 ui->passEdit1->installEventFilter(
this);
39 ui->passEdit2->installEventFilter(
this);
40 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"));
51 ui->stakingCheckBox->setChecked(
false);
52 ui->stakingCheckBox->hide();
55 ui->warningLabel->setText(tr(
"This operation needs your wallet passphrase to unlock the wallet.<br/><br/>(Wallet may appear not responding as it rescans for all transactions)<br/><br/>"));
56 ui->warningLabel->setAlignment(Qt::AlignHCenter);
57 ui->passLabel2->hide();
58 ui->passEdit2->hide();
59 ui->passLabel3->hide();
60 ui->passEdit3->hide();
61 setWindowTitle(tr(
"Unlock Wallet"));
64 ui->warningLabel->setText(tr(
"This operation needs your wallet passphrase to decrypt the wallet."));
65 ui->passLabel2->hide();
66 ui->passEdit2->hide();
67 ui->passLabel3->hide();
68 ui->passEdit3->hide();
69 setWindowTitle(tr(
"Decrypt Wallet"));
72 setWindowTitle(tr(
"Change Passphrase"));
73 ui->warningLabel->setText(tr(
"Enter the old and new passphrase to the wallet."));
79 ui->stakingCheckBox->setChecked(
true);
82 ui->stakingCheckBox->setChecked(
false);
87 ui->stakingCheckBox->hide();
100 ui->passEdit1->setText(QString(
" ").repeated(
ui->passEdit1->text().size()));
101 ui->passEdit2->setText(QString(
" ").repeated(
ui->passEdit2->text().size()));
102 ui->passEdit3->setText(QString(
" ").repeated(
ui->passEdit3->text().size()));
111 oldpass.reserve(MAX_PASSPHRASE_SIZE);
112 newpass1.reserve(MAX_PASSPHRASE_SIZE);
113 newpass2.reserve(MAX_PASSPHRASE_SIZE);
116 oldpass.assign(
ui->passEdit1->text().toStdString().c_str());
117 newpass1.assign(
ui->passEdit2->text().toStdString().c_str());
118 newpass2.assign(
ui->passEdit3->text().toStdString().c_str());
122 if (newpass1.empty() || newpass2.empty()) {
126 QMessageBox::StandardButton retval = QMessageBox::question(
this, tr(
"Confirm Wallet Encryption"),
127 tr(
"Warning: If you encrypt your wallet and lose your passphrase, you will <b>LOSE ALL OF YOUR COINS</b>!") +
"<br><br>" + tr(
"Are you sure you wish to encrypt your wallet?"),
128 QMessageBox::Yes | QMessageBox::Cancel,
129 QMessageBox::Cancel);
130 if (retval == QMessageBox::Yes) {
131 if (newpass1 == newpass2) {
133 QMessageBox::warning(
this, tr(
"Wallet Encrypted"),
135 tr(
"PRCY will close now to finish the encryption process. "
136 "Remember that encrypting your wallet cannot fully protect "
137 "your PRCYs from being stolen by malware infecting your computer.") +
139 tr(
"IMPORTANT: Any previous backups you have made of your wallet file "
140 "should be replaced with the newly generated, encrypted wallet file. "
141 "For security reasons, previous backups of the unencrypted wallet file "
142 "will become useless as soon as you start using the new, encrypted wallet.") +
144 QApplication::quit();
147 msgBox.setWindowTitle(
"Wallet Encryption Failed");
148 msgBox.setText(
"Wallet encryption failed due to an internal error. Your wallet was not encrypted. Please try again.");
150 msgBox.setIcon(QMessageBox::Critical);
156 msgBox.setWindowTitle(
"Wallet Encryption Failed");
157 msgBox.setText(
"The supplied passphrases do not match. Please try again.");
159 msgBox.setIcon(QMessageBox::Critical);
170 msgBox.setWindowTitle(
"Wallet Unlock Failed");
171 msgBox.setText(
"The passphrase entered for the wallet unlock was incorrect. Please try again.");
173 msgBox.setIcon(QMessageBox::Critical);
182 msgBox.setWindowTitle(
"Wallet Decryption Failed");
183 msgBox.setText(
"The passphrase entered for the wallet decryption was incorrect. Please try again.");
185 msgBox.setIcon(QMessageBox::Critical);
192 if (newpass1 == newpass2) {
195 msgBox.setWindowTitle(
"Passphrase Change Successful");
196 msgBox.setText(
"Wallet passphrase was successfully changed.\nPlease remember your passphrase as there is no way to recover it.");
198 msgBox.setIcon(QMessageBox::Information);
203 msgBox.setWindowTitle(
"Wallet Encryption Failed");
204 msgBox.setText(
"The passphrase entered for the wallet decryption was incorrect. Please try again.");
206 msgBox.setIcon(QMessageBox::Critical);
211 msgBox.setWindowTitle(
"Wallet Encryption Failed");
212 msgBox.setText(
"The supplied passphrases do not match. Please try again.");
214 msgBox.setIcon(QMessageBox::Critical);
224 bool acceptable =
false;
227 acceptable = !
ui->passEdit2->text().isEmpty() && !
ui->passEdit3->text().isEmpty();
232 acceptable = !
ui->passEdit1->text().isEmpty();
235 acceptable = !
ui->passEdit1->text().isEmpty() && !
ui->passEdit2->text().isEmpty() && !
ui->passEdit3->text().isEmpty();
238 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(acceptable);
244 if (
event->type() == QEvent::KeyPress) {
245 QKeyEvent* ke =
static_cast<QKeyEvent*
>(
event);
246 if (ke->key() == Qt::Key_CapsLock) {
250 ui->capsLabel->setText(tr(
"Warning: The Caps Lock key is on!"));
252 ui->capsLabel->clear();
255 return QWidget::event(
event);
266 if (
event->type() == QEvent::KeyPress) {
267 QKeyEvent* ke =
static_cast<QKeyEvent*
>(
event);
268 QString str = ke->text();
269 if (str.length() != 0) {
270 const QChar* psz = str.unicode();
271 bool fShift = (ke->modifiers() & Qt::ShiftModifier) != 0;
272 if ((fShift && *psz >=
'a' && *psz <=
'z') || (!fShift && *psz >=
'A' && *psz <=
'Z')) {
274 ui->capsLabel->setText(tr(
"Warning: The Caps Lock key is on!"));
275 }
else if (psz->isLetter()) {
277 ui->capsLabel->clear();
281 return QDialog::eventFilter(
object,
event);
286 ui->passEdit1->setEchoMode(
ui->showPassphraseCheckBox->checkState() == Qt::Checked ? QLineEdit::Normal : QLineEdit::Password );
287 ui->passEdit2->setEchoMode(
ui->showPassphraseCheckBox->checkState() == Qt::Checked ? QLineEdit::Normal : QLineEdit::Password );
288 ui->passEdit3->setEchoMode(
ui->showPassphraseCheckBox->checkState() == Qt::Checked ? QLineEdit::Normal : QLineEdit::Password );