From dfe4149ebc095b95f1bd918d5aa7e227a0d3136e Mon Sep 17 00:00:00 2001 From: ajnart Date: Wed, 23 Aug 2023 22:25:04 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20`password-requirements`=20?= =?UTF-8?q?progress=20bar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Password/password-requirements.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/components/Password/password-requirements.tsx b/src/components/Password/password-requirements.tsx index 2a25a54fb..fcaa8c569 100644 --- a/src/components/Password/password-requirements.tsx +++ b/src/components/Password/password-requirements.tsx @@ -11,15 +11,19 @@ const requirements = [ ]; function getStrength(password: string) { - let multiplier = password.length >= minPasswordLength ? 0 : 1; + let score = 0; + const goal = requirements.length + 1; requirements.forEach((requirement) => { - if (!requirement.re.test(password)) { - multiplier += 1; + if (requirement.re.test(password)) { + score += 1; } }); + if (password.length >= minPasswordLength) { + score += 1; + } + return (score / goal) * 100; - return Math.max(100 - (100 / (requirements.length + 1)) * multiplier, 10); } export const PasswordRequirements = ({ value }: { value: string }) => {