import { Translated } from "@/components/translated"; import { lowerCaseValidator, numberValidator, symbolValidator, upperCaseValidator } from "@/helpers/validators"; import { PasswordComplexitySettings } from "@zitadel/proto/zitadel/settings/v2/password_settings_pb"; import { useTranslations } from "next-intl"; type Props = { passwordComplexitySettings: PasswordComplexitySettings; password: string; equals: boolean; }; function CheckIcon({ title }: { title: string }) { return ( {title} ); } function CrossIcon({ title }: { title: string }) { return ( {title} ); } function renderIcon(matched: boolean, t: ReturnType) { return matched ? : ; } const desc = "text-14px leading-4 text-input-light-label dark:text-input-dark-label"; export function PasswordComplexity({ passwordComplexitySettings, password, equals }: Props) { const t = useTranslations("password"); const hasMinLength = password?.length >= passwordComplexitySettings.minLength; const hasSymbol = symbolValidator(password); const hasNumber = numberValidator(password); const hasUppercase = upperCaseValidator(password); const hasLowercase = lowerCaseValidator(password); return (
{passwordComplexitySettings.minLength != undefined ? (
{renderIcon(hasMinLength, t)}
) : null} {passwordComplexitySettings.requiresSymbol && (
{renderIcon(hasSymbol, t)}
)} {passwordComplexitySettings.requiresNumber && (
{renderIcon(hasNumber, t)}
)} {passwordComplexitySettings.requiresUppercase && (
{renderIcon(hasUppercase, t)}
)} {passwordComplexitySettings.requiresLowercase && (
{renderIcon(hasLowercase, t)}
)}
{renderIcon(equals, t)}
); }