Wladimir J. van der Laan
13 years ago
16 changed files with 582 additions and 9 deletions
@ -0,0 +1,186 @@
@@ -0,0 +1,186 @@
|
||||
#include "askpassphrasedialog.h" |
||||
#include "ui_askpassphrasedialog.h" |
||||
|
||||
#include "guiconstants.h" |
||||
#include "walletmodel.h" |
||||
|
||||
#include <QMessageBox> |
||||
#include <QPushButton> |
||||
|
||||
AskPassphraseDialog::AskPassphraseDialog(Mode mode, QWidget *parent) : |
||||
QDialog(parent), |
||||
ui(new Ui::AskPassphraseDialog), |
||||
mode(mode), |
||||
model(0) |
||||
{ |
||||
ui->setupUi(this); |
||||
ui->passEdit1->setMaxLength(MAX_PASSPHRASE_SIZE); |
||||
ui->passEdit2->setMaxLength(MAX_PASSPHRASE_SIZE); |
||||
ui->passEdit3->setMaxLength(MAX_PASSPHRASE_SIZE); |
||||
|
||||
switch(mode) |
||||
{ |
||||
case Encrypt: // Ask passphrase x2
|
||||
ui->passLabel1->hide(); |
||||
ui->passEdit1->hide(); |
||||
ui->warningLabel->setText(tr("Enter the new passphrase to the wallet.<br/>Please use a passphrase of <b>10 or more random characters</b>, or <b>eight or more words</b>.")); |
||||
setWindowTitle(tr("Encrypt wallet")); |
||||
break; |
||||
case Unlock: // Ask passphrase
|
||||
ui->warningLabel->setText(tr("This operation needs your wallet passphrase to unlock the wallet.")); |
||||
ui->passLabel2->hide(); |
||||
ui->passEdit2->hide(); |
||||
ui->passLabel3->hide(); |
||||
ui->passEdit3->hide(); |
||||
setWindowTitle(tr("Unlock wallet")); |
||||
break; |
||||
case Decrypt: // Ask passphrase
|
||||
ui->warningLabel->setText(tr("This operation needs your wallet passphrase to decrypt the wallet.")); |
||||
ui->passLabel2->hide(); |
||||
ui->passEdit2->hide(); |
||||
ui->passLabel3->hide(); |
||||
ui->passEdit3->hide(); |
||||
setWindowTitle(tr("Decrypt wallet")); |
||||
break; |
||||
case ChangePass: // Ask old passphrase + new passphrase x2
|
||||
setWindowTitle(tr("Change passphrase")); |
||||
ui->warningLabel->setText(tr("Enter the old and new passphrase to the wallet.")); |
||||
break; |
||||
} |
||||
resize(minimumSize()); // Get rid of extra space in dialog
|
||||
|
||||
textChanged(); |
||||
connect(ui->passEdit1, SIGNAL(textChanged(QString)), this, SLOT(textChanged())); |
||||
connect(ui->passEdit2, SIGNAL(textChanged(QString)), this, SLOT(textChanged())); |
||||
connect(ui->passEdit3, SIGNAL(textChanged(QString)), this, SLOT(textChanged())); |
||||
} |
||||
|
||||
AskPassphraseDialog::~AskPassphraseDialog() |
||||
{ |
||||
// Attempt to overwrite text so that they do not linger around in memory
|
||||
ui->passEdit1->setText(QString(" ").repeated(ui->passEdit1->text().size())); |
||||
ui->passEdit2->setText(QString(" ").repeated(ui->passEdit2->text().size())); |
||||
ui->passEdit3->setText(QString(" ").repeated(ui->passEdit3->text().size())); |
||||
delete ui; |
||||
} |
||||
|
||||
void AskPassphraseDialog::setModel(WalletModel *model) |
||||
{ |
||||
this->model = model; |
||||
} |
||||
|
||||
void AskPassphraseDialog::accept() |
||||
{ |
||||
std::string oldpass, newpass1, newpass2; |
||||
// TODO: mlock memory / munlock on return so they will not be swapped out, really need "mlockedstring" wrapper class to do this safely
|
||||
oldpass.reserve(MAX_PASSPHRASE_SIZE); |
||||
newpass1.reserve(MAX_PASSPHRASE_SIZE); |
||||
newpass2.reserve(MAX_PASSPHRASE_SIZE); |
||||
oldpass.assign(ui->passEdit1->text().toStdString()); |
||||
newpass1.assign(ui->passEdit2->text().toStdString()); |
||||
newpass2.assign(ui->passEdit3->text().toStdString()); |
||||
|
||||
switch(mode) |
||||
{ |
||||
case Encrypt: { |
||||
if(newpass1.empty() || newpass2.empty()) |
||||
{ |
||||
// Cannot encrypt with empty passphrase
|
||||
break; |
||||
} |
||||
QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm wallet encryption"), |
||||
tr("WARNING: If you encrypt your wallet and lose your passphrase, you will <b>LOSE ALL OF YOUR BITCOINS</b>!\nAre you sure you wish to encrypt your wallet?"), |
||||
QMessageBox::Yes|QMessageBox::Cancel, |
||||
QMessageBox::Cancel); |
||||
if(retval == QMessageBox::Yes) |
||||
{ |
||||
if(newpass1 == newpass2) |
||||
{ |
||||
if(model->setWalletEncrypted(true, newpass1)) |
||||
{ |
||||
QMessageBox::warning(this, tr("Wallet encrypted"), |
||||
tr("Remember that encrypting your wallet cannot fully protect your bitcoins from being stolen by malware infecting your computer.")); |
||||
} |
||||
else |
||||
{ |
||||
QMessageBox::critical(this, tr("Wallet encryption failed"), |
||||
tr("Wallet encryption failed due to an internal error. Your wallet was not encrypted.")); |
||||
} |
||||
QDialog::accept(); // Success
|
||||
} |
||||
else |
||||
{ |
||||
QMessageBox::critical(this, tr("Wallet encryption failed"), |
||||
tr("The supplied passphrases do not match.")); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
QDialog::reject(); // Cancelled
|
||||
} |
||||
} break; |
||||
case Unlock: |
||||
if(!model->setWalletLocked(false, oldpass)) |
||||
{ |
||||
QMessageBox::critical(this, tr("Wallet unlock failed"), |
||||
tr("The passphrase entered for the wallet decryption was incorrect.")); |
||||
} |
||||
else |
||||
{ |
||||
QDialog::accept(); // Success
|
||||
} |
||||
break; |
||||
case Decrypt: |
||||
if(!model->setWalletEncrypted(false, oldpass)) |
||||
{ |
||||
QMessageBox::critical(this, tr("Wallet decryption failed"), |
||||
tr("The passphrase entered for the wallet decryption was incorrect.")); |
||||
} |
||||
else |
||||
{ |
||||
QDialog::accept(); // Success
|
||||
} |
||||
break; |
||||
case ChangePass: |
||||
if(newpass1 == newpass2) |
||||
{ |
||||
if(model->changePassphrase(oldpass, newpass1)) |
||||
{ |
||||
QMessageBox::information(this, tr("Wallet encrypted"), |
||||
tr("Wallet passphrase was succesfully changed.")); |
||||
QDialog::accept(); // Success
|
||||
} |
||||
else |
||||
{ |
||||
QMessageBox::critical(this, tr("Wallet encryption failed"), |
||||
tr("The passphrase entered for the wallet decryption was incorrect.")); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
QMessageBox::critical(this, tr("Wallet encryption failed"), |
||||
tr("The supplied passphrases do not match.")); |
||||
} |
||||
break; |
||||
} |
||||
} |
||||
|
||||
void AskPassphraseDialog::textChanged() |
||||
{ |
||||
// Validate input, set Ok button to enabled when accepable
|
||||
bool acceptable = false; |
||||
switch(mode) |
||||
{ |
||||
case Encrypt: // New passphrase x2
|
||||
acceptable = !ui->passEdit2->text().isEmpty() && !ui->passEdit3->text().isEmpty(); |
||||
break; |
||||
case Unlock: // Old passphrase x1
|
||||
case Decrypt: |
||||
acceptable = !ui->passEdit1->text().isEmpty(); |
||||
break; |
||||
case ChangePass: // Old passphrase x1, new passphrase x2
|
||||
acceptable = !ui->passEdit1->text().isEmpty() && !ui->passEdit2->text().isEmpty() && !ui->passEdit3->text().isEmpty(); |
||||
break; |
||||
} |
||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(acceptable); |
||||
} |
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
#ifndef ASKPASSPHRASEDIALOG_H |
||||
#define ASKPASSPHRASEDIALOG_H |
||||
|
||||
#include <QDialog> |
||||
|
||||
namespace Ui { |
||||
class AskPassphraseDialog; |
||||
} |
||||
|
||||
class WalletModel; |
||||
|
||||
class AskPassphraseDialog : public QDialog |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
enum Mode { |
||||
Encrypt, // Ask passphrase x2
|
||||
Unlock, // Ask passphrase
|
||||
ChangePass, // Ask old passphrase + new passphrase x2
|
||||
Decrypt // Ask passphrase
|
||||
}; |
||||
|
||||
explicit AskPassphraseDialog(Mode mode, QWidget *parent = 0); |
||||
~AskPassphraseDialog(); |
||||
|
||||
void accept(); |
||||
|
||||
void setModel(WalletModel *model); |
||||
|
||||
private: |
||||
Ui::AskPassphraseDialog *ui; |
||||
Mode mode; |
||||
WalletModel *model; |
||||
|
||||
private slots: |
||||
void textChanged(); |
||||
}; |
||||
|
||||
#endif // ASKPASSPHRASEDIALOG_H
|
@ -0,0 +1,148 @@
@@ -0,0 +1,148 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<ui version="4.0"> |
||||
<class>AskPassphraseDialog</class> |
||||
<widget class="QDialog" name="AskPassphraseDialog"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>589</width> |
||||
<height>228</height> |
||||
</rect> |
||||
</property> |
||||
<property name="sizePolicy"> |
||||
<sizepolicy hsizetype="Preferred" vsizetype="Minimum"> |
||||
<horstretch>0</horstretch> |
||||
<verstretch>0</verstretch> |
||||
</sizepolicy> |
||||
</property> |
||||
<property name="minimumSize"> |
||||
<size> |
||||
<width>550</width> |
||||
<height>0</height> |
||||
</size> |
||||
</property> |
||||
<property name="windowTitle"> |
||||
<string>Dialog</string> |
||||
</property> |
||||
<layout class="QVBoxLayout" name="verticalLayout"> |
||||
<item> |
||||
<widget class="QLabel" name="warningLabel"> |
||||
<property name="text"> |
||||
<string>TextLabel</string> |
||||
</property> |
||||
<property name="textFormat"> |
||||
<enum>Qt::RichText</enum> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<layout class="QFormLayout" name="formLayout"> |
||||
<property name="fieldGrowthPolicy"> |
||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum> |
||||
</property> |
||||
<item row="1" column="0"> |
||||
<widget class="QLabel" name="passLabel1"> |
||||
<property name="text"> |
||||
<string>Enter passphrase</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="1" column="1"> |
||||
<widget class="QLineEdit" name="passEdit1"> |
||||
<property name="echoMode"> |
||||
<enum>QLineEdit::Password</enum> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="2" column="0"> |
||||
<widget class="QLabel" name="passLabel2"> |
||||
<property name="text"> |
||||
<string>New passphrase</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="2" column="1"> |
||||
<widget class="QLineEdit" name="passEdit2"> |
||||
<property name="echoMode"> |
||||
<enum>QLineEdit::Password</enum> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="3" column="0"> |
||||
<widget class="QLabel" name="passLabel3"> |
||||
<property name="text"> |
||||
<string>Repeat new passphrase</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="3" column="1"> |
||||
<widget class="QLineEdit" name="passEdit3"> |
||||
<property name="echoMode"> |
||||
<enum>QLineEdit::Password</enum> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
<item> |
||||
<spacer name="verticalSpacer"> |
||||
<property name="orientation"> |
||||
<enum>Qt::Vertical</enum> |
||||
</property> |
||||
<property name="sizeHint" stdset="0"> |
||||
<size> |
||||
<width>20</width> |
||||
<height>40</height> |
||||
</size> |
||||
</property> |
||||
</spacer> |
||||
</item> |
||||
<item> |
||||
<widget class="QDialogButtonBox" name="buttonBox"> |
||||
<property name="orientation"> |
||||
<enum>Qt::Horizontal</enum> |
||||
</property> |
||||
<property name="standardButtons"> |
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
<resources/> |
||||
<connections> |
||||
<connection> |
||||
<sender>buttonBox</sender> |
||||
<signal>accepted()</signal> |
||||
<receiver>AskPassphraseDialog</receiver> |
||||
<slot>accept()</slot> |
||||
<hints> |
||||
<hint type="sourcelabel"> |
||||
<x>248</x> |
||||
<y>254</y> |
||||
</hint> |
||||
<hint type="destinationlabel"> |
||||
<x>157</x> |
||||
<y>274</y> |
||||
</hint> |
||||
</hints> |
||||
</connection> |
||||
<connection> |
||||
<sender>buttonBox</sender> |
||||
<signal>rejected()</signal> |
||||
<receiver>AskPassphraseDialog</receiver> |
||||
<slot>reject()</slot> |
||||
<hints> |
||||
<hint type="sourcelabel"> |
||||
<x>316</x> |
||||
<y>260</y> |
||||
</hint> |
||||
<hint type="destinationlabel"> |
||||
<x>286</x> |
||||
<y>274</y> |
||||
</hint> |
||||
</hints> |
||||
</connection> |
||||
</connections> |
||||
</ui> |
After Width: | Height: | Size: 1.2 KiB |
Loading…
Reference in new issue