5 #if defined(HAVE_CONFIG_H) 19 #include <QMessageBox> 20 #include <QPushButton> 28 m_passphrase_out(passphrase_out)
48 ui->
warningLabel->setText(tr(
"Enter the new passphrase for the wallet.<br/>Please use a passphrase of <b>ten or more random characters</b>, or <b>eight or more words</b>."));
51 setWindowTitle(tr(
"Encrypt wallet"));
54 ui->
warningLabel->setText(tr(
"This operation needs your wallet passphrase to unlock the wallet."));
59 setWindowTitle(tr(
"Unlock wallet"));
62 ui->
warningLabel->setText(tr(
"This operation needs your wallet passphrase to decrypt the wallet."));
67 setWindowTitle(tr(
"Decrypt wallet"));
70 setWindowTitle(tr(
"Change passphrase"));
71 ui->
warningLabel->setText(tr(
"Enter the old passphrase and new passphrase for the wallet."));
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());
113 if(newpass1.empty() || newpass2.empty())
118 QMessageBox::StandardButton retval = QMessageBox::question(
this, tr(
"Confirm wallet encryption"),
119 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?"),
120 QMessageBox::Yes|QMessageBox::Cancel,
121 QMessageBox::Cancel);
122 if(retval == QMessageBox::Yes)
124 if(newpass1 == newpass2)
126 QString encryption_reminder = tr(
"Remember that encrypting your wallet cannot fully protect " 127 "your bitcoins from being stolen by malware infecting your computer.");
130 QMessageBox::warning(
this, tr(
"Wallet to be encrypted"),
132 tr(
"Your wallet is about to be encrypted. ") + encryption_reminder +
135 assert(
model !=
nullptr);
138 QMessageBox::warning(
this, tr(
"Wallet encrypted"),
140 tr(
"Your wallet is now encrypted. ") + encryption_reminder +
142 tr(
"IMPORTANT: Any previous backups you have made of your wallet file " 143 "should be replaced with the newly generated, encrypted wallet file. " 144 "For security reasons, previous backups of the unencrypted wallet file " 145 "will become useless as soon as you start using the new, encrypted wallet.") +
150 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
151 tr(
"Wallet encryption failed due to an internal error. Your wallet was not encrypted."));
158 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
159 tr(
"The supplied passphrases do not match."));
170 QMessageBox::critical(
this, tr(
"Wallet unlock failed"),
171 tr(
"The passphrase entered for the wallet decryption was incorrect."));
175 }
catch (
const std::runtime_error& e) {
176 QMessageBox::critical(
this, tr(
"Wallet unlock failed"), e.what());
182 QMessageBox::critical(
this, tr(
"Wallet decryption failed"),
183 tr(
"The passphrase entered for the wallet decryption was incorrect."));
191 if(newpass1 == newpass2)
195 QMessageBox::information(
this, tr(
"Wallet encrypted"),
196 tr(
"Wallet passphrase was successfully changed."));
201 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
202 tr(
"The passphrase entered for the wallet decryption was incorrect."));
207 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
208 tr(
"The supplied passphrases do not match."));
217 bool acceptable =
false;
231 ui->
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(acceptable);
237 if (event->type() == QEvent::KeyPress) {
238 QKeyEvent *ke =
static_cast<QKeyEvent *
>(
event);
239 if (ke->key() == Qt::Key_CapsLock) {
243 ui->
capsLabel->setText(tr(
"Warning: The Caps Lock key is on!"));
248 return QWidget::event(event);
254 const auto mode = show ? QLineEdit::Normal : QLineEdit::Password;
268 if (event->type() == QEvent::KeyPress) {
269 QKeyEvent *ke =
static_cast<QKeyEvent *
>(
event);
270 QString str = ke->text();
271 if (str.length() != 0) {
272 const QChar *psz = str.unicode();
273 bool fShift = (ke->modifiers() & Qt::ShiftModifier) != 0;
274 if ((fShift && *psz >=
'a' && *psz <=
'z') || (!fShift && *psz >=
'A' && *psz <=
'Z')) {
276 ui->
capsLabel->setText(tr(
"Warning: The Caps Lock key is on!"));
277 }
else if (psz->isLetter()) {
283 return QDialog::eventFilter(
object, event);
289 edit->setText(QString(
" ").repeated(edit->text().size()));
void setupUi(QDialog *AskPassphraseDialog)
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()
void handleCloseWindowShortcut(QWidget *w)
bool changePassphrase(const SecureString &oldPass, const SecureString &newPass)
SecureString * m_passphrase_out
AskPassphraseDialog(Mode mode, QWidget *parent, SecureString *passphrase_out=nullptr)
QDialogButtonBox * buttonBox
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.
QCheckBox * toggleShowPasswordButton
Ask old passphrase + new passphrase twice.
void setModel(WalletModel *model)