-
Notifications
You must be signed in to change notification settings - Fork 954
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
Custom feedback messages #124
Conversation
+1 This would be great to use it with other languges |
👍 |
1 similar comment
+1 |
@lowe any interest on this? I am getting emails from people asking me how to use it. Based on the +1s in this PR, it seems users need a way to modify the feedback messages. Happy to change the code if you don't like the approach. |
+1 |
1 similar comment
+1 |
Hi @paulballesty, Thanks for the PR. I'm happy to merge but have three requests to work through first:
|
I agree with @lowe for the dictionary, otherwise numbers aren't very descriptive when overriding! |
@paulballesty's PR (now with a dictionnary thanks to 55b9ce5) looks nice and is a must have! Any chance having it merged soon @lowe? |
@the-question I didn't have time to test the last changes properly. I'll try to find some time this week. Sorry for the delay! |
Thank @paulballesty for PR. I tried to use it but I encountered a few problems:
returns empty string in suggestions unnecessary:
so in function I attached feedback.patch and also tape tests for feedback (test/test-feedback.coffee). |
@lowe finally found time to work on this 😄 (public holiday in Australia 🇦🇺 ).
In the last commits I moved the
Done
I did something a bit different here. Instead of excluding the message if it's not present in I included tests for the feedback component, I think that's gonna make things easier in the future 😄 . Also cherry-picked those tests in another branch without all the custom feedback logic to check that these changes aren't breaking anything in the feedback logic, you can check that here. |
|
||
get_match_feedback: (match, is_sole_match) -> | ||
switch match.pattern | ||
when 'dictionary' | ||
@get_dictionary_match_feedback match, is_sole_match | ||
|
||
when 'spatial' | ||
layout = match.graph.toUpperCase() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this used somewhere?
src/main.coffee
Outdated
{ user_inputs, feedback_messages } = options | ||
else | ||
user_inputs = [] | ||
feedback_messages = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ this is the code moving user_inputs
in a options
object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
options
are a bit better because they make future changes easier. I get error when compile, so I suggest the following version:
zxcvbn = (password, options = {}) ->
user_inputs = []
feedback_messages = {}
if options instanceof Array
user_inputs = options # backward-compatibility
else
user_inputs = options.user_inputs if options.user_inputs
feedback_messages = options.feedback_messages if options.feedback_messages
suggestions = [] | ||
for suggestion_key in suggestion_keys | ||
message = @get_message(suggestion_key) | ||
suggestions.push message if message? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add message to suggestions only if not empty:
suggestions.push message if message? and message != ''
Array of suggestions with empty string like [ '' ]
or [ '', 'Avoid sequences']
is complication for displaying feedback. Empty string occurs if message is present in custom messages and has a falsy value.
Hi @lowe, any chance of merging this in the near future? Seems ready to me! |
src/main.coffee
Outdated
zxcvbn = (password, options = {}) -> | ||
if options instanceof Array | ||
user_inputs = options # backward-compatibility | ||
else if typeof options === 'object' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@paulballesty I don't know CoffeeScript well but strict equality checks using "===" is not valid syntax in CoffeeScript my local build failed using your PR. CoffeeScript converts all loose checks into strict equality checks by default so using "===" is not needed here.
src/main.coffee
Outdated
if options instanceof Array | ||
user_inputs = options # backward-compatibility | ||
else if typeof options === 'object' | ||
{ user_inputs, feedback_messages } = options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@paulballesty In that case user_input
should be initialised with an empty array to mimic the old behaviour. Otherwise an exception is thrown in main.coffee L20 when you trying to iterate over the values of an undefined user_input array.
Hi, any chance to have t his merged any time soon? |
Also would love to see this in master. |
In case anyone is interested, we have temporarily released this branch as npm package: |
Here's a MIT licensed french translation of most of the feedback strings. It's a .po file for another project, but you can probably adapt it quickly. |
Please merge this PR as soon as possible! the world is full of non english speakers who need secure passwords! :) |
+1 |
NOTE: given that this changes the interface, it should be published as a major version bump, so it doesn't interfere with exiting users of yarn/npm. |
@@ -203,7 +203,28 @@ result.calc_time # how long it took zxcvbn to calculate an answer, | |||
# in milliseconds. | |||
```` | |||
|
|||
The optional `user_inputs` argument is an array of strings that zxcvbn will treat as an extra dictionary. This can be whatever list of strings you like, but is meant for user inputs from other fields of the form, like name and email. That way a password that includes a user's personal information can be heavily penalized. This list is also good for site-specific vocabulary — Acme Brick Co. might want to include ['acme', 'brick', 'acmebrick', etc]. | |||
The optional `options` argument is an object that can contain the following optional properties: | |||
- `user_inputs` is an array of strings that zxcvbn will treat as an extra dictionary. This can be whatever list of strings you like, but is meant for user inputs from other fields of the form, like name and email. That way a password that includes a user's personal information can be heavily penalized. This list is also good for site-specific vocabulary — Acme Brick Co. might want to include ['acme', 'brick', 'acmebrick', etc]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should probably be userInputs
and feedbackMessages
respectively... this is JavaScript.
zxcvbn = (password, user_inputs = []) -> | ||
zxcvbn = (password, options = {}) -> | ||
if options instanceof Array | ||
user_inputs = options # backward-compatibility |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
userInputs
and feedbackMessages
?
Closing this PR. It's been open for more than 2 years. |
This need to be merged not closed! |
@tracker1 Looks like it was backwards compatible with line 9 of |
@cdroulers It does seem that way... the issue, to me is the prior version didn't force a convention, as it was an argument. Now that you're passing an object, imho the object structure should conform to JS naming conventions (camel-case as opposed to snake-case). |
@tracker1 Oh, absolutely, I posted this in reference to your previous comment! |
@paulballesty, are you open to this sort of feature being merged (whether in this form or another)? I understand wanting to tidy up a bit, but it looked like it was starting to gain some traction again? |
@xtrasimplicity I am not an owner of the repo so I cannot merge the feature myself. I left the PR open for more than 2 years. I closed it assuming there's no intention of merging it. |
Thanks for clarifying, @paulballesty - much appreciated. :) @lowe, Are you able to shed some light on this? |
@lowe @paulballesty Just found this PR, and this is something I need 👍 Can I do anything to help test, tidy up, etc? Would be nice to have it merged and bumped to a new version. |
Added i18n support for Password Reset ([as far as currently possible with zxcvbn](dropbox/zxcvbn#124)). This mainly involved moving the HTML elements generated inside the JavaScript code to the corresponding view fragment. Revised passwordMeter.js and view fragment for better UX, i.e. logic of alerts and appearance. Added German translation of new message properties. A port forward will be provided upon (positive) feedback on these changes. What do you think?
Translation options would be a very common thing in my opinion. I thought I found a decent library, but seeing a PR like this not being used to its potential is a bit of a let down. |
Is this going somewhere? For now I'm using this package published by @ctavan (thanks!). |
Yet another one of those "looks good, looks good, looks good, oh crap, need to find another library"... |
I need this feature and I'd be ready to rebase this onto the current master. @lowe would you check and merge the resulting pr? |
I need to use the library in an internationalized website, which means that I need the feedback messages in other languages. I added the optional third parameter
options
, in where you can pass afeedback_messages
Array-like object with custom messages.Do you guys think it worth adding this to the library?
Example usages:
Redifining all the messages
Changing an specific message