Add password repeat check for entry passwords.

This commit is contained in:
Florian Geyer 2012-04-17 16:04:49 +02:00 committed by Felix Geyer
parent fc8f1231c6
commit 7c70eccaf7
2 changed files with 41 additions and 1 deletions

View File

@ -23,6 +23,7 @@
#include <QtGui/QListWidget>
#include <QtGui/QStackedLayout>
#include <QtGui/QMessageBox>
#include "core/Entry.h"
#include "core/Group.h"
@ -74,6 +75,8 @@ EditEntryWidget::EditEntryWidget(QWidget* parent)
connect(m_mainUi->togglePasswordButton, SIGNAL(toggled(bool)), SLOT(togglePassword(bool)));
connect(m_mainUi->expireCheck, SIGNAL(toggled(bool)), m_mainUi->expireDatePicker, SLOT(setEnabled(bool)));
connect(m_mainUi->passwordEdit, SIGNAL(textEdited(QString)), SLOT(setPasswordCheckColors()));
connect(m_mainUi->passwordRepeatEdit, SIGNAL(textEdited(QString)), SLOT(setPasswordCheckColors()));
connect(m_ui->buttonBox, SIGNAL(accepted()), SLOT(saveEntry()));
connect(m_ui->buttonBox, SIGNAL(rejected()), SLOT(cancel()));
@ -83,6 +86,10 @@ EditEntryWidget::~EditEntryWidget()
{
}
const QColor EditEntryWidget::normalColor = Qt::white;
const QColor EditEntryWidget::correctSoFarColor = QColor(255, 205, 15);
const QColor EditEntryWidget::errorColor = QColor(255, 125, 125);
void EditEntryWidget::loadEntry(Entry* entry, bool create, const QString& groupName)
{
m_entry = entry;
@ -99,6 +106,7 @@ void EditEntryWidget::loadEntry(Entry* entry, bool create, const QString& groupN
m_mainUi->urlEdit->setText(entry->url());
m_mainUi->passwordEdit->setText(entry->password());
m_mainUi->passwordRepeatEdit->setText(entry->password());
setPasswordCheckColors();
m_mainUi->expireCheck->setChecked(entry->timeInfo().expires());
m_mainUi->expireDatePicker->setDateTime(entry->timeInfo().expiryTime());
m_mainUi->togglePasswordButton->setChecked(true);
@ -118,7 +126,10 @@ void EditEntryWidget::saveEntry()
m_entry->setTitle(m_mainUi->titleEdit->text());
m_entry->setUsername(m_mainUi->usernameEdit->text());
m_entry->setUrl(m_mainUi->urlEdit->text());
// TODO check password repeat field
if (!passwordsEqual()) {
QMessageBox::warning(this, tr("Error"), tr("Different passwords supplied."));
return;
}
m_entry->setPassword(m_mainUi->passwordEdit->text());
m_entry->setExpires(m_mainUi->expireCheck->isChecked());
QDateTime dateTime(m_mainUi->expireDatePicker->dateTime());
@ -147,3 +158,25 @@ void EditEntryWidget::togglePassword(bool checked)
m_mainUi->passwordEdit->setEchoMode(checked ? QLineEdit::Password : QLineEdit::Normal);
m_mainUi->passwordRepeatEdit->setEchoMode(checked ? QLineEdit::Password : QLineEdit::Normal);
}
bool EditEntryWidget::passwordsEqual()
{
return m_mainUi->passwordEdit->text() == m_mainUi->passwordRepeatEdit->text();
}
void EditEntryWidget::setPasswordCheckColors()
{
QPalette pal;
if (passwordsEqual()) {
pal.setColor(QPalette::Base, normalColor);
}
else {
if (m_mainUi->passwordEdit->text().startsWith(m_mainUi->passwordRepeatEdit->text())) {
pal.setColor(QPalette::Base, correctSoFarColor);
}
else {
pal.setColor(QPalette::Base, errorColor);
}
}
m_mainUi->passwordRepeatEdit->setPalette(pal);
}

View File

@ -46,6 +46,10 @@ public:
void loadEntry(Entry* entry, bool create, const QString& groupName);
static const QColor normalColor;
static const QColor correctSoFarColor;
static const QColor errorColor;
Q_SIGNALS:
void editFinished(bool accepted);
@ -53,6 +57,7 @@ private Q_SLOTS:
void saveEntry();
void cancel();
void togglePassword(bool checked);
void setPasswordCheckColors();
private:
Entry* m_entry;
@ -69,6 +74,8 @@ private:
EntryAttachments* m_entryAttachments;
EntryAttributes* m_entryAttributes;
bool passwordsEqual();
Q_DISABLE_COPY(EditEntryWidget)
};