Skip to content

Commit

Permalink
Minor fixes after code review
Browse files Browse the repository at this point in the history
  • Loading branch information
wolframroesler committed Dec 10, 2019
1 parent 4c88902 commit 04e78c4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 35 deletions.
28 changes: 14 additions & 14 deletions src/core/PasswordHealth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@
#include "zxcvbn.h"

PasswordHealth::PasswordHealth(double entropy)
: entropy_(entropy)
, score_(entropy)
: m_entropy(entropy)
, m_score(entropy)
{
switch (quality()) {
case Quality::bad:
case Quality::poor:
reason_ = QApplication::tr("Very weak password");
details_ = QApplication::tr("Password entropy is %1 bit").arg(QString::number(entropy_, 'f', 2));
m_reason = QApplication::tr("Very weak password");
m_details = QApplication::tr("Password entropy is %1 bit").arg(QString::number(m_entropy, 'f', 2));
break;

case Quality::weak:
reason_ = QApplication::tr("Weak password");
details_ = QApplication::tr("Password entropy is %1 bit").arg(QString::number(entropy_, 'f', 2));
m_reason = QApplication::tr("Weak password");
m_details = QApplication::tr("Password entropy is %1 bit").arg(QString::number(m_entropy, 'f', 2));
break;

case Quality::good:
Expand Down Expand Up @@ -88,14 +88,14 @@ PasswordHealth::PasswordHealth(QSharedPointer<Database> db, QString pwd, Cache*
const auto& used = (*cache)[pwd];
const auto count = used.size();
if (count > 1) {
score_ -= penalty * (count - 1);
addTo(reason_, QApplication::tr("Password is used %1 times").arg(QString::number(count)));
addTo(details_, used.join('\n'));
m_score -= penalty * (count - 1);
addTo(m_reason, QApplication::tr("Password is used %1 times").arg(QString::number(count)));
addTo(m_details, used.join('\n'));

// Don't allow re-used passwords to be considered "good"
// no matter how great their entropy is.
if (score_ > 64) {
score_ = 64;
if (m_score > 64) {
m_score = 64;
}
}
}
Expand All @@ -104,9 +104,9 @@ PasswordHealth::PasswordHealth(QSharedPointer<Database> db, const Entry& entry,
: PasswordHealth(db, entry.password(), cache)
{
if (entry.isExpired()) {
score_ = 0;
addTo(reason_, QApplication::tr("Password has expired"));
addTo(details_,
m_score = 0;
addTo(m_reason, QApplication::tr("Password has expired"));
addTo(m_details,
QApplication::tr("Password expiry was %1")
.arg(entry.timeInfo().expiryTime().toString(Qt::DefaultLocaleShortDate)));
}
Expand Down
14 changes: 7 additions & 7 deletions src/core/PasswordHealth.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class PasswordHealth
*/
int score() const
{
return score_;
return m_score;
}

/*
Expand Down Expand Up @@ -82,25 +82,25 @@ class PasswordHealth
*/
QString reason() const
{
return reason_;
return m_reason;
}
QString details() const
{
return details_;
return m_details;
}

/*
* The password entropy, in bits.
*/
double entropy() const
{
return entropy_;
return m_entropy;
}

private:
double entropy_ = 0.0;
int score_ = 0;
QString reason_, details_;
double m_entropy = 0.0;
int m_score = 0;
QString m_reason, m_details;
void addTo(QString& to, QString newText);
};

Expand Down
25 changes: 14 additions & 11 deletions src/gui/reports/ReportsWidgetHealthcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ namespace
};

explicit Health(QSharedPointer<Database> db)
: db_(db)
: m_db(db)
{
gatherHealth(db->rootGroup()->groupsRecursive(true));
}

const QVector<Item>& items() const
{
return items_;
return m_items;
}

private:
QSharedPointer<Database> db_;
QVector<Item> items_;
PasswordHealth::Cache cache_;
QSharedPointer<Database> m_db;
QVector<Item> m_items;
PasswordHealth::Cache m_cache;

void gatherHealth(const QList<Group*>&);
};
Expand All @@ -83,24 +83,26 @@ void Health::gatherHealth(const QList<Group*>& groups)
}

for (const auto* entry : group->entries()) {
if (entry->isRecycled())
if (entry->isRecycled()) {
continue;
}

// Skip entries with empty password
if (entry->password().isEmpty())
if (entry->password().isEmpty()) {
continue;
}

// Add entry if its password isn't at least "good"
const auto item = Item(db_, *group, *entry, cache_);
const auto item = Item(m_db, *group, *entry, m_cache);
if (item.health.quality() < PasswordHealth::Quality::good) {
items_.append(item);
m_items.append(item);
}
}
}

// Sort the result so that the worst passwords (least score)
// are at the top
std::sort(items_.begin(), items_.end());
std::sort(m_items.begin(), m_items.end());
}

ReportsWidgetHealthcheck::ReportsWidgetHealthcheck(QWidget* parent)
Expand Down Expand Up @@ -215,8 +217,9 @@ void ReportsWidgetHealthcheck::calculateHealth()

void ReportsWidgetHealthcheck::emitEntryActivated(const QModelIndex& index)
{
if (!index.isValid())
if (!index.isValid()) {
return;
}

const auto r = m_row2entry[index.row()];
const auto group = r.first;
Expand Down
7 changes: 4 additions & 3 deletions src/gui/reports/ReportsWidgetStatistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace
// Ctor does all the work
explicit Stats(QSharedPointer<Database> db)
: modified(QFileInfo(db->filePath()).lastModified())
, db_(db)
, m_db(db)
{
gatherStats(db->rootGroup()->groupsRecursive(true));
}
Expand Down Expand Up @@ -93,7 +93,7 @@ namespace
}

private:
QSharedPointer<Database> db_;
QSharedPointer<Database> m_db;
QHash<QString, int> m_passwords;

void gatherStats(const QList<Group*>& groups)
Expand Down Expand Up @@ -132,7 +132,8 @@ namespace
}

// Speed up Zxcvbn process by excluding very long passwords and most passphrases
if (pwd.size() < 25 && PasswordHealth(db_, *entry).quality() <= PasswordHealth::Quality::weak) {
if (pwd.size() < 25
&& PasswordHealth(m_db, *entry).quality() <= PasswordHealth::Quality::weak) {
++nPwdsWeak;
}

Expand Down

0 comments on commit 04e78c4

Please sign in to comment.