-
Notifications
You must be signed in to change notification settings - Fork 11
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
Correctly count length of password with multibyte characters #485
Conversation
Before, any non-ASCII characters were simply ignored for password strength.
60732fd
to
f6c9a22
Compare
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.
Looks good to me. Now, I have one password with emojis 🥳
src/lib/PasswordStrength.js
Outdated
count.upperCase += 1; | ||
} else if (characters[i].match(/[0-9]/g)) { | ||
count.numbers += 1; | ||
} else if (characters[i].match(/[^a-z]/)) { |
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.
Subjective take: Easier to read
!characters[i].match(/[a-z]/)
, instead of
characters[i].match(/[^a-z]/)
Probably not worth changing
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.
Thanks, this is a great suggestion! Code readability is a priority in the security-relevant Keyguard.
LGTM |
I would include some comments on why using the spread operator makes a difference in the lenght. Otherwise, LGTM 👍🏼 |
This PR fixes the way password character length is counted to use the recommended method from MDN for strings with potential multibyte characters.
Additionally, this method is applied to the password strength calculator to always handle full characters, not "lone surrogates".