Skip to content

Commit cc37f90

Browse files
Show suggestions only when no specific warning is present
When zxcvbn provides a warning (specific pattern diagnosis), suppress the generic suggestions they typically say the same thing in different words. Suggestions still appear when there is no warning but improvements can be suggested (e.g. score 1-2 without a pattern match).
1 parent 6edb43b commit cc37f90

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

EssentialCSharp.Web/wwwroot/js/password-strength.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,17 @@ function updateMeter(container, score, feedback, crackTimesDisplay) {
9696
const requirementsList = container.querySelector('.password-requirements');
9797
const requirementsPending = requirementsList && !requirementsList.classList.contains('d-none');
9898

99-
// Warning: what's wrong (null for score >= 3)
99+
// Warning: specific diagnosis of what pattern was detected (null for score >= 3)
100+
const warning = requirementsPending ? '' : (feedback.warning ?? '');
100101
if (warningEl) {
101-
const warning = requirementsPending ? '' : (feedback.warning ?? '');
102102
warningEl.textContent = warning;
103103
warningEl.classList.toggle('d-none', !warning);
104104
}
105105

106-
// Suggestions: how to improve
106+
// Suggestions: generic improvement tips — only shown when there is no specific warning,
107+
// since both would otherwise say the same thing in different words.
107108
if (suggestionsEl) {
108-
const tips = requirementsPending ? [] : (feedback.suggestions ?? []).filter(Boolean);
109+
const tips = (!requirementsPending && !warning) ? (feedback.suggestions ?? []).filter(Boolean) : [];
109110
suggestionsEl.textContent = tips.join(' ');
110111
suggestionsEl.classList.toggle('d-none', tips.length === 0);
111112
}

0 commit comments

Comments
 (0)