Skip to content

Commit

Permalink
Add password strength indicator to PasswordEditWidget
Browse files Browse the repository at this point in the history
Fixes #7437 (entry edit view only)
Fixes #5220
  • Loading branch information
jmdana committed Apr 13, 2022
1 parent 692c95b commit 402d273
Show file tree
Hide file tree
Showing 19 changed files with 368 additions and 140 deletions.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ set(keepassx_SOURCES
gui/MessageBox.cpp
gui/MessageWidget.cpp
gui/OpVaultOpenWidget.cpp
gui/PasswordEdit.cpp
gui/PasswordWidget.cpp
gui/PasswordGeneratorWidget.cpp
gui/ApplicationSettingsWidget.cpp
gui/Icons.cpp
Expand Down
8 changes: 5 additions & 3 deletions src/autotype/PickcharsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ PickcharsDialog::PickcharsDialog(const QString& string, QWidget* parent)
// Remove last selected character
auto shortcut = new QShortcut(Qt::Key_Backspace, this);
connect(shortcut, &QShortcut::activated, this, [this] {
auto text = m_ui->selectedChars->text();
// auto text = m_ui->selectedChars->text();
auto text = m_ui->selectedChars->getText();
// m_ui->selectedChars->setText(text.left(text.size() - 1));
m_ui->selectedChars->setText(text.left(text.size() - 1));
});
// Submit the form
Expand Down Expand Up @@ -134,7 +136,7 @@ void PickcharsDialog::downPressed()

QString PickcharsDialog::selectedChars()
{
return m_ui->selectedChars->text();
return m_ui->selectedChars->getText();
}

bool PickcharsDialog::pressTab()
Expand All @@ -149,7 +151,7 @@ void PickcharsDialog::charSelected()
return;
}

m_ui->selectedChars->setText(m_ui->selectedChars->text() + btn->property("char").toChar());
m_ui->selectedChars->setText(m_ui->selectedChars->getText() + btn->property("char").toChar());
}

void PickcharsDialog::showEvent(QShowEvent* event)
Expand Down
8 changes: 4 additions & 4 deletions src/autotype/PickcharsDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<layout class="QGridLayout" name="charsGrid"/>
</item>
<item>
<widget class="PasswordEdit" name="selectedChars">
<widget class="PasswordWidget" name="selectedChars">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
Expand Down Expand Up @@ -74,9 +74,9 @@
</widget>
<customwidgets>
<customwidget>
<class>PasswordEdit</class>
<extends>QLineEdit</extends>
<header>gui/PasswordEdit.h</header>
<class>PasswordWidget</class>
<extends>QWidget</extends>
<header>gui/PasswordWidget.h</header>
</customwidget>
</customwidgets>
<tabstops>
Expand Down
8 changes: 4 additions & 4 deletions src/gui/DatabaseOpenWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ void DatabaseOpenWidget::openDatabase()
emit dialogFinished(true);
clearForms();
} else {
if (!isOnQuickUnlockScreen() && m_ui->editPassword->text().isEmpty() && !m_retryUnlockWithEmptyPassword) {
if (!isOnQuickUnlockScreen() && m_ui->editPassword->getText().isEmpty() && !m_retryUnlockWithEmptyPassword) {
QScopedPointer<QMessageBox> msgBox(new QMessageBox(this));
msgBox->setIcon(QMessageBox::Critical);
msgBox->setWindowTitle(tr("Unlock failed and no password given"));
Expand Down Expand Up @@ -348,15 +348,15 @@ QSharedPointer<CompositeKey> DatabaseOpenWidget::buildDatabaseKey()
return databaseKey;
}

if (!m_ui->editPassword->text().isEmpty() || m_retryUnlockWithEmptyPassword) {
databaseKey->addKey(QSharedPointer<PasswordKey>::create(m_ui->editPassword->text()));
if (!m_ui->editPassword->getText().isEmpty() || m_retryUnlockWithEmptyPassword) {
databaseKey->addKey(QSharedPointer<PasswordKey>::create(m_ui->editPassword->getText()));
}

auto lastKeyFiles = config()->get(Config::LastKeyFiles).toHash();
lastKeyFiles.remove(m_filename);

auto key = QSharedPointer<FileKey>::create();
QString keyFilename = m_ui->keyFileLineEdit->text();
QString keyFilename = m_ui->keyFileLineEdit->getText();
if (!keyFilename.isEmpty()) {
QString errorMsg;
if (!key->load(keyFilename, &errorMsg)) {
Expand Down
10 changes: 5 additions & 5 deletions src/gui/DatabaseOpenWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
</widget>
</item>
<item>
<widget class="PasswordEdit" name="editPassword">
<widget class="PasswordWidget" name="editPassword">
<property name="accessibleName">
<string>Password field</string>
</property>
Expand Down Expand Up @@ -380,7 +380,7 @@
<number>0</number>
</property>
<item row="0" column="1">
<widget class="PasswordEdit" name="keyFileLineEdit">
<widget class="PasswordWidget" name="keyFileLineEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
Expand Down Expand Up @@ -617,9 +617,9 @@
</widget>
<customwidgets>
<customwidget>
<class>PasswordEdit</class>
<extends>QLineEdit</extends>
<header>gui/PasswordEdit.h</header>
<class>PasswordWidget</class>
<extends>QWidget</extends>
<header>gui/PasswordWidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
Expand Down
6 changes: 3 additions & 3 deletions src/gui/KeePass1OpenWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ void KeePass1OpenWidget::openDatabase()
KeePass1Reader reader;

QString password;
QString keyFileName = m_ui->keyFileLineEdit->text();
QString keyFileName = m_ui->keyFileLineEdit->getText();

if (!m_ui->editPassword->text().isEmpty() || m_retryUnlockWithEmptyPassword) {
password = m_ui->editPassword->text();
if (!m_ui->editPassword->getText().isEmpty() || m_retryUnlockWithEmptyPassword) {
password = m_ui->editPassword->getText();
}

QFile file(m_filename);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/OpVaultOpenWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void OpVaultOpenWidget::openDatabase()
OpVaultReader reader;

QString password;
password = m_ui->editPassword->text();
password = m_ui->editPassword->getText();

QDir opVaultDir(m_filename);

Expand Down
6 changes: 3 additions & 3 deletions src/gui/PasswordGeneratorWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void PasswordGeneratorWidget::setStandaloneMode(bool standalone)

QString PasswordGeneratorWidget::getGeneratedPassword()
{
return m_ui->editNewPassword->text();
return m_ui->editNewPassword->getText();
}

void PasswordGeneratorWidget::regeneratePassword()
Expand Down Expand Up @@ -295,13 +295,13 @@ void PasswordGeneratorWidget::applyPassword()
{
saveSettings();
m_passwordGenerated = true;
emit appliedPassword(m_ui->editNewPassword->text());
emit appliedPassword(m_ui->editNewPassword->getText());
emit closed();
}

void PasswordGeneratorWidget::copyPassword()
{
clipboard()->setText(m_ui->editNewPassword->text());
clipboard()->setText(m_ui->editNewPassword->getText());
}

void PasswordGeneratorWidget::passwordLengthChanged(int length)
Expand Down
34 changes: 17 additions & 17 deletions src/gui/PasswordGeneratorWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,17 @@
</layout>
</item>
<item row="0" column="0">
<widget class="PasswordEdit" name="editNewPassword">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>450</width>
<height>0</height>
<widget class="PasswordWidget" name="editNewPassword">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>450</width>
<height>0</height>
</size>
</property>
<property name="accessibleName">
Expand Down Expand Up @@ -989,12 +989,12 @@ QProgressBar::chunk {
</layout>
</widget>
<customwidgets>
<customwidget>
<class>PasswordEdit</class>
<extends>QLineEdit</extends>
<header>gui/PasswordEdit.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>PasswordWidget</class>
<extends>QWidget</extends>
<header>gui/PasswordWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>editNewPassword</tabstop>
Expand Down
Loading

0 comments on commit 402d273

Please sign in to comment.