6 #if defined(HAVE_CONFIG_H) 11 #include "ui_askpassphrasedialog.h" 19 #include <QMessageBox> 20 #include <QPushButton> 31 ui->passEdit1->setMinimumSize(
ui->passEdit1->sizeHint());
32 ui->passEdit2->setMinimumSize(
ui->passEdit2->sizeHint());
33 ui->passEdit3->setMinimumSize(
ui->passEdit3->sizeHint());
35 ui->passEdit1->setMaxLength(MAX_PASSPHRASE_SIZE);
36 ui->passEdit2->setMaxLength(MAX_PASSPHRASE_SIZE);
37 ui->passEdit3->setMaxLength(MAX_PASSPHRASE_SIZE);
40 ui->passEdit1->installEventFilter(
this);
41 ui->passEdit2->installEventFilter(
this);
42 ui->passEdit3->installEventFilter(
this);
47 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>."));
48 ui->passLabel1->hide();
49 ui->passEdit1->hide();
50 setWindowTitle(tr(
"Encrypt wallet"));
53 ui->warningLabel->setText(tr(
"This operation needs your wallet passphrase to unlock the wallet."));
54 ui->passLabel2->hide();
55 ui->passEdit2->hide();
56 ui->passLabel3->hide();
57 ui->passEdit3->hide();
58 setWindowTitle(tr(
"Unlock wallet"));
61 ui->warningLabel->setText(tr(
"This operation needs your wallet passphrase to decrypt the wallet."));
62 ui->passLabel2->hide();
63 ui->passEdit2->hide();
64 ui->passLabel3->hide();
65 ui->passEdit3->hide();
66 setWindowTitle(tr(
"Decrypt wallet"));
69 setWindowTitle(tr(
"Change passphrase"));
70 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 RAVENS</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(
"%1 will close now to finish the encryption process. " 127 "Remember that encrypting your wallet cannot fully protect " 128 "your ravens from being stolen by malware infecting your computer.").arg(tr(
PACKAGE_NAME)) +
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.") +
135 QApplication::quit();
139 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
140 tr(
"Wallet encryption failed due to an internal error. Your wallet was not encrypted."));
146 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
147 tr(
"The supplied passphrases do not match."));
158 QMessageBox::critical(
this, tr(
"Wallet unlock failed"),
159 tr(
"The passphrase entered for the wallet decryption was incorrect."));
169 QMessageBox::critical(
this, tr(
"Wallet decryption failed"),
170 tr(
"The passphrase entered for the wallet decryption was incorrect."));
178 if(newpass1 == newpass2)
182 QMessageBox::information(
this, tr(
"Wallet encrypted"),
183 tr(
"Wallet passphrase was successfully changed."));
188 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
189 tr(
"The passphrase entered for the wallet decryption was incorrect."));
194 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
195 tr(
"The supplied passphrases do not match."));
204 bool acceptable =
false;
208 acceptable = !
ui->passEdit2->text().isEmpty() && !
ui->passEdit3->text().isEmpty();
212 acceptable = !
ui->passEdit1->text().isEmpty();
215 acceptable = !
ui->passEdit1->text().isEmpty() && !
ui->passEdit2->text().isEmpty() && !
ui->passEdit3->text().isEmpty();
218 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(acceptable);
224 if (event->type() == QEvent::KeyPress) {
225 QKeyEvent *ke =
static_cast<QKeyEvent *
>(
event);
226 if (ke->key() == Qt::Key_CapsLock) {
230 ui->capsLabel->setText(tr(
"Warning: The Caps Lock key is on!"));
232 ui->capsLabel->clear();
235 return QWidget::event(event);
246 if (event->type() == QEvent::KeyPress) {
247 QKeyEvent *ke =
static_cast<QKeyEvent *
>(
event);
248 QString str = ke->text();
249 if (str.length() != 0) {
250 const QChar *psz = str.unicode();
251 bool fShift = (ke->modifiers() & Qt::ShiftModifier) != 0;
252 if ((fShift && *psz >=
'a' && *psz <=
'z') || (!fShift && *psz >=
'A' && *psz <=
'Z')) {
254 ui->capsLabel->setText(tr(
"Warning: The Caps Lock key is on!"));
255 }
else if (psz->isLetter()) {
257 ui->capsLabel->clear();
261 return QDialog::eventFilter(
object, event);
264 static void SecureClearQLineEdit(QLineEdit* edit)
267 edit->setText(QString(
" ").repeated(edit->text().size()));
273 SecureClearQLineEdit(
ui->passEdit1);
274 SecureClearQLineEdit(
ui->passEdit2);
275 SecureClearQLineEdit(
ui->passEdit3);
bool event(QEvent *event)
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Ask passphrase twice and encrypt.
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 Raven 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)