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

Add password strength meter #1949

Merged
merged 8 commits into from
Oct 3, 2024
Merged

Add password strength meter #1949

merged 8 commits into from
Oct 3, 2024

Conversation

OKendigelyan
Copy link
Contributor

@OKendigelyan OKendigelyan commented Sep 25, 2024

Proposed changes

Task link

Types of changes

  • Bugfix
  • New feature
  • Refactor
  • Breaking change
  • UI fix

Steps to reproduce

Screenshots

Web

Screen.Recording.2024-09-25.at.15.19.18.mov

Desktop

Screen.Recording.2024-09-25.at.15.20.37.mov

Checklist

  • Tests that prove my fix is effective or that my feature works have been added
  • Documentation has been added (if appropriate)
  • Screenshots are added (if any UI changes have been made)
  • All TODOs have a corresponding task created (and the link is attached to it)

Copy link

vercel bot commented Sep 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
umami-v2-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 3, 2024 1:17pm
umami-v2-web-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 3, 2024 1:17pm

@OKendigelyan OKendigelyan force-pushed the add-password-strength-meter branch from 5093f76 to 348cd03 Compare September 25, 2024 14:08
@OKendigelyan OKendigelyan marked this pull request as ready for review September 25, 2024 14:18
@OKendigelyan OKendigelyan force-pushed the add-password-strength-meter branch 2 times, most recently from a386786 to d91a8b5 Compare September 25, 2024 14:26
@OKendigelyan OKendigelyan force-pushed the add-password-strength-meter branch from 5158e2b to d7f1d41 Compare September 25, 2024 15:00
@OKendigelyan OKendigelyan force-pushed the add-password-strength-meter branch from d7f1d41 to 1ae6f1d Compare September 25, 2024 15:03
Copy link
Contributor

@asiia-trilitech asiia-trilitech left a comment

Choose a reason for hiding this comment

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

Thank you, Oleg - great addition to the password checks 🔥

Please check comments before merging

);
};

type UsePasswordValidationProps = {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, optional: maybe move UsePasswordValidationProps & usePasswordValidation hook to the top of the file?

apps/desktop/src/components/PasswordInput.tsx Outdated Show resolved Hide resolved
if (validate) {
const validateResult = validate(val);

if (checkPasswordStrength && validateResult === true) {
Copy link
Contributor

Choose a reason for hiding this comment

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

validate?: (val: string) => string | boolean;

Is string result for the errors?

validateResult can be a string? won't validateResult === true return true as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

validateResult could be either a sting or boolean
A non-empty string is a truthy value, but is not strictly equal to true

minLength = MIN_LENGTH,
validate,
...rest
}: PasswordInputProps<T, U>) => {
const { register } = useFormContext<T>();
const [showPassword, setShowPassword] = useState<boolean>(false);
const { validatePassword, PasswordStrengthBar } = usePasswordValidation({
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe validatePasswordStrength to avoid confusion with validate function from the input

Copy link
Contributor

Choose a reason for hiding this comment

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

Please apply comments from desktop version of PasswordInput as well

const colors = [colorScheme, "red.500", "yellow.500", "green.500"];
const passwordError = form.formState.errors[inputName];

const getColor = (index: number) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe getSectionColor & sectionIndex?

Copy link
Contributor

Choose a reason for hiding this comment

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

@OKendigelyan please consider renaming / adding a comment - it's a bit hard to understand what the function from a first glance


type PasswordStrengthBarProps = {
score: number;
colorScheme: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe defaultSectionColoror defaultColor here?

@@ -55,6 +57,7 @@ export const ChangePasswordMenu = () => {
data-testid="new-password-confirmation"
inputName="newPasswordConfirmation"
label="Confirm password"
minLength={0}
Copy link
Contributor

Choose a reason for hiding this comment

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

shall we make it the default for the password input so that we don't need to repeat it everywhere?

switch (score) {
case 1:
case 2:
return "Weak";
Copy link
Contributor

Choose a reason for hiding this comment

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

capitalized strength looks strange in UI tbh, maybe use the lowercased one?

Copy link
Contributor

@asiia-trilitech asiia-trilitech left a comment

Choose a reason for hiding this comment

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

Thanks for the changes @OKendigelyan
Approved with some minor comments 🚀

const colors = [colorScheme, "red.500", "yellow.500", "green.500"];
const passwordError = form.formState.errors[inputName];

const getColor = (index: number) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

@OKendigelyan please consider renaming / adding a comment - it's a bit hard to understand what the function from a first glance

};

type UsePasswordValidationProps = {
color?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe defaultBarColor or something similar? Not very obvious what this param is for with the current name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think color would be more concise in this case, given that the only place where color can be used as a prop in this hook is the PasswordStrengthBar, so I don't think it can be too confusing

const [showPassword, setShowPassword] = useState<boolean>(false);
const { validatePasswordStrength, PasswordStrengthBar } = usePasswordValidation({
inputName,
minLength,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why MIN_LENGTH is defined here and not in usePasswordValidation?
Could it have values other than 12?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it to use it here for the error message?
Maybe instead we can keep everything related to the validation in usePasswordValidation, and export the minLength from there?

const color = useColor();

const error = errors[inputName];
const errorMessage = error?.message as string;

const handleValidate = (val: string) => {
if (validate) {
const validateResult = validate(val);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe validationResult?

@OKendigelyan OKendigelyan force-pushed the add-password-strength-meter branch from 9ff1492 to 84be53f Compare October 3, 2024 13:15
@OKendigelyan OKendigelyan enabled auto-merge (squash) October 3, 2024 13:23
@OKendigelyan OKendigelyan merged commit 192b5d3 into main Oct 3, 2024
6 checks passed
@OKendigelyan OKendigelyan deleted the add-password-strength-meter branch October 3, 2024 13:26
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.

3 participants