"use client"; // icons import { CircleCheck } from "lucide-react"; // helpers import { cn } from "@/helpers/common.helper"; import { getPasswordStrength } from "@/helpers/password.helper"; type Props = { password: string; }; export const PasswordStrengthMeter: React.FC = (props: Props) => { const { password } = props; const strength = getPasswordStrength(password); let bars = []; let text = ""; let textColor = ""; if (password.length === 0) { bars = [`bg-[#F0F0F3]`, `bg-[#F0F0F3]`, `bg-[#F0F0F3]`]; text = "Password requirements"; } else if (password.length < 8) { bars = [`bg-[#DC3E42]`, `bg-[#F0F0F3]`, `bg-[#F0F0F3]`]; text = "Password is too short"; textColor = `text-[#DC3E42]`; } else if (strength < 3) { bars = [`bg-[#FFBA18]`, `bg-[#FFBA18]`, `bg-[#F0F0F3]`]; text = "Password is weak"; textColor = `text-[#FFBA18]`; } else { bars = [`bg-[#3E9B4F]`, `bg-[#3E9B4F]`, `bg-[#3E9B4F]`]; text = "Password is strong"; textColor = `text-[#3E9B4F]`; } const criteria = [ { label: "Min 8 characters", isValid: password.length >= 8 }, { label: "Min 1 upper-case letter", isValid: /[A-Z]/.test(password) }, { label: "Min 1 number", isValid: /\d/.test(password) }, { label: "Min 1 special character", isValid: /[!@#$%^&*]/.test(password) }, ]; return (
{bars.map((color, index) => (
))}

{text}

{criteria.map((criterion, index) => (
{criterion.label}
))}
); };