5 #if defined(HAVE_CONFIG_H) 19 #include <QMessageBox> 20 #include <QPushButton> 26 m_passphrase_out(passphrase_out)
46 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>."));
49 setWindowTitle(tr(
"Encrypt wallet"));
52 ui->
warningLabel->setText(tr(
"This operation needs your wallet passphrase to unlock the wallet."));
57 setWindowTitle(tr(
"Unlock wallet"));
60 setWindowTitle(tr(
"Change passphrase"));
61 ui->
warningLabel->setText(tr(
"Enter the old passphrase and new passphrase for the wallet."));
93 oldpass.assign(std::string_view{
ui->
passEdit1->text().toStdString()});
94 newpass1.assign(std::string_view{
ui->
passEdit2->text().toStdString()});
95 newpass2.assign(std::string_view{
ui->
passEdit3->text().toStdString()});
102 if(newpass1.empty() || newpass2.empty())
107 QMessageBox::StandardButton retval = QMessageBox::question(
this, tr(
"Confirm wallet encryption"),
108 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?"),
109 QMessageBox::Yes|QMessageBox::Cancel,
110 QMessageBox::Cancel);
111 if(retval == QMessageBox::Yes)
113 if(newpass1 == newpass2)
115 QString encryption_reminder = tr(
"Remember that encrypting your wallet cannot fully protect " 116 "your bitcoins from being stolen by malware infecting your computer.");
119 QMessageBox::warning(
this, tr(
"Wallet to be encrypted"),
121 tr(
"Your wallet is about to be encrypted. ") + encryption_reminder +
126 QMessageBox::warning(
this, tr(
"Wallet encrypted"),
128 tr(
"Your wallet is now encrypted. ") + encryption_reminder +
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.") +
136 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
137 tr(
"Wallet encryption failed due to an internal error. Your wallet was not encrypted."));
144 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
145 tr(
"The supplied passphrases do not match."));
157 if (oldpass.find(
'\0') == std::string::npos) {
158 QMessageBox::critical(
this, tr(
"Wallet unlock failed"),
159 tr(
"The passphrase entered for the wallet decryption was incorrect."));
161 QMessageBox::critical(
this, tr(
"Wallet unlock failed"),
162 tr(
"The passphrase entered for the wallet decryption is incorrect. " 163 "It contains a null character (ie - a zero byte). " 164 "If the passphrase was set with a version of this software prior to 25.0, " 165 "please try again with only the characters up to — but not including — " 166 "the first null character. If this is successful, please set a new " 167 "passphrase to avoid this issue in the future."));
175 }
catch (
const std::runtime_error& e) {
176 QMessageBox::critical(
this, tr(
"Wallet unlock failed"), e.what());
180 if(newpass1 == newpass2)
184 QMessageBox::information(
this, tr(
"Wallet encrypted"),
185 tr(
"Wallet passphrase was successfully changed."));
191 if (oldpass.find(
'\0') == std::string::npos) {
192 QMessageBox::critical(
this, tr(
"Passphrase change failed"),
193 tr(
"The passphrase entered for the wallet decryption was incorrect."));
195 QMessageBox::critical(
this, tr(
"Passphrase change failed"),
196 tr(
"The old passphrase entered for the wallet decryption is incorrect. " 197 "It contains a null character (ie - a zero byte). " 198 "If the passphrase was set with a version of this software prior to 25.0, " 199 "please try again with only the characters up to — but not including — " 200 "the first null character."));
206 QMessageBox::critical(
this, tr(
"Wallet encryption failed"),
207 tr(
"The supplied passphrases do not match."));
216 bool acceptable =
false;
229 ui->
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(acceptable);
235 if (
event->type() == QEvent::KeyPress) {
236 QKeyEvent *ke =
static_cast<QKeyEvent *
>(
event);
237 if (ke->key() == Qt::Key_CapsLock) {
241 ui->
capsLabel->setText(tr(
"Warning: The Caps Lock key is on!"));
246 return QWidget::event(
event);
252 const auto mode = show ? QLineEdit::Normal : QLineEdit::Password;
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()) {
281 return QDialog::eventFilter(
object,
event);
287 edit->setText(QString(
" ").repeated(edit->text().size()));
void setupUi(QDialog *AskPassphraseDialog)
static const int MAX_PASSPHRASE_SIZE
Utility functions used by the Bitcoin Qt UI.
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)
constexpr auto dialog_flags
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)
bool setWalletEncrypted(const SecureString &passphrase)
QDialogButtonBox * buttonBox
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.
QCheckBox * toggleShowPasswordButton
Ask old passphrase + new passphrase twice.
void setModel(WalletModel *model)