Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix password strength feedback for empty password #6008

Merged
merged 5 commits into from
Feb 28, 2022

Conversation

aduth
Copy link
Member

@aduth aduth commented Feb 28, 2022

Previously: #5776 (LG-5461)

This improves a few things around password strength feedback:

  • Marks the password strings as used in the JavaScript bundles, to ensure they're included in the locale bundles generated by RailsI18nWebpackPlugin (2902141)
  • Joins multiple password strength feedback strings as individual sentences, so that they don't create a run-on sentence (24b2ddc, before, after)
  • Generates password strength feedback only if password is non-empty, so that the feedback matches the initial state on a new page load, per the expectation of LG-5461 (ca73309)

Steps to reproduce:

  1. Create a new account
  2. Complete account creation up to "Create a strong password"
  3. Enter some text in the field
  4. Delete that text
Before After
Screen Shot 2022-02-28 at 11 22 24 AM Screen Shot 2022-02-28 at 11 28 25 AM

**Why**: To ensure they're included in the locale bundles generated by RailsI18nWebpackPlugin
**Why**: So that they don't create a run-on sentence, since each string does not terminate as a full sentence
**Why**: So that the feedback matches the initial state on a new page load, per the expectation of LG-5461
@@ -69,6 +70,7 @@ function getFeedback(z) {
// i18n-tasks-use t('zxcvbn.feedback.this_is_a_top_10_common_password')
// i18n-tasks-use t('zxcvbn.feedback.this_is_a_very_common_password')
// i18n-tasks-use t('zxcvbn.feedback.this_is_similar_to_a_commonly_used_password')
// i18n-tasks-use t('zxcvbn.feedback.use_a_few_words_avoid_common_phrases')
// i18n-tasks-use t('zxcvbn.feedback.use_a_longer_keyboard_pattern_with_more_turns')
return t(`zxcvbn.feedback.${snakeCase(str)}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't the first time we've had some missing translations with zxcvbn (#5776 comes to mind) is there a better way we can list these, or maybe a safer fallback we can use than to print the slug?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't the first time we've had some missing translations with zxcvbn (#5776 comes to mind) is there a better way we can list these, or maybe a safer fallback we can use than to print the slug?

Yeah, these changes should have been included in #5776. As far as preventative measures, I mentioned at the time that it's a bit hard to test for. There was also a reference to formigarafa/zxcvbn-rb#4 where similar issues had been reported upstream. Since that time, there's been a comment of all strings we should cross-reference to our translations.

Aside from that, some ideas we could consider:

  • Auto-include all zxcvbn.feedback keys into the locale string extraction
  • Don't print original key if there is no translation (at least avoid the non-human-readable text from being shown)

Copy link
Contributor

@zachmargolis zachmargolis Feb 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like both those, including all zxcvbn and also not passing through the key (maybe we add a default: option like ruby i18n has, and we call back to something general like "please use a different password")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another idea is to use TypeScript to enforce coverage for all strings, but the DefinitelyTyped types appear to only list out the warnings, and not the suggestions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I double-checked the list in formigarafa/zxcvbn-rb#4 (comment) and made sure we have all strings listed there. I also added a spec in 6649e74 for the specific behavior being introduced here for an empty password. I was going to add a spec for the joining, though from looking at the source code, it doesn't appear there's a combination that could result in a multi-suggestion result being used, since we defer to a warning if it's present.

The ideas in #6008 (comment) are reasonable improvements, but moving forward I might suggest to propose an upstream improvement to the DefinitelyTyped type definitions to include all possible suggestions, then update our implementation to strongly type the feedback mappings, e.g.:

const FEEDBACK: Record<ZXCVBNFeedbackWarning & ZXCVBNFeedbackSuggestion, string> = {
  "Straight rows of keys are easy to guess": '...',
  // ...
};

changelog: Bug Fixes, Password Entry, Add missing messages for password strength feedback
@aduth aduth marked this pull request as ready for review February 28, 2022 19:56
Copy link
Contributor

@zachmargolis zachmargolis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aduth aduth merged commit 054e892 into main Feb 28, 2022
@aduth aduth deleted the aduth-lg-5461-empty-strength branch February 28, 2022 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants