Files
zitadel/apps/login/ui/PasswordComplexity.tsx

98 lines
2.7 KiB
TypeScript
Raw Normal View History

2023-04-26 15:14:28 +02:00
import {
lowerCaseValidator,
numberValidator,
symbolValidator,
upperCaseValidator,
} from "#/utils/validators";
2023-05-22 11:58:44 +02:00
import { PasswordComplexitySettings } from "@zitadel/server";
2023-04-26 15:14:28 +02:00
type Props = {
2023-05-22 11:58:44 +02:00
passwordComplexitySettings: PasswordComplexitySettings;
2023-04-26 15:14:28 +02:00
password: string;
equals: boolean;
};
const check = (
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth={1.5}
stroke="currentColor"
2023-04-26 18:36:09 +02:00
className="w-6 h-6 las la-check text-green-500 dark:text-green-500 mr-2 text-lg"
2023-06-05 17:46:17 +02:00
role="img"
2023-04-26 15:14:28 +02:00
>
2023-06-05 17:46:17 +02:00
<title>Matches</title>
2023-04-26 15:14:28 +02:00
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M4.5 12.75l6 6 9-13.5"
/>
</svg>
);
const cross = (
<svg
className="w-6 h-6 las la-times text-warn-light-500 dark:text-warn-dark-500 mr-2 text-lg"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth={1.5}
stroke="currentColor"
2023-06-05 17:46:17 +02:00
role="img"
2023-04-26 15:14:28 +02:00
>
2023-06-05 17:46:17 +02:00
<title>Doesn't match</title>
2023-04-26 15:14:28 +02:00
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M6 18L18 6M6 6l12 12"
/>
</svg>
);
const desc =
"text-14px leading-4 text-input-light-label dark:text-input-dark-label";
export default function PasswordComplexity({
2023-05-22 11:58:44 +02:00
passwordComplexitySettings,
2023-04-26 15:14:28 +02:00
password,
equals,
}: Props) {
2023-05-22 11:58:44 +02:00
const hasMinLength = password?.length >= passwordComplexitySettings.minLength;
2023-04-26 15:14:28 +02:00
const hasSymbol = symbolValidator(password);
const hasNumber = numberValidator(password);
const hasUppercase = upperCaseValidator(password);
const hasLowercase = lowerCaseValidator(password);
return (
<div className="mb-4 grid grid-cols-2 gap-x-8 gap-y-2">
2023-06-05 17:46:17 +02:00
{passwordComplexitySettings.minLength != undefined ? (
<div className="flex flex-row items-center">
{hasMinLength ? check : cross}
<span className={desc}>
Password length {passwordComplexitySettings.minLength}
</span>
</div>
) : <span />}
2023-04-26 15:14:28 +02:00
<div className="flex flex-row items-center">
{hasSymbol ? check : cross}
<span className={desc}>has Symbol</span>
</div>
<div className="flex flex-row items-center">
{hasNumber ? check : cross}
<span className={desc}>has Number</span>
</div>
<div className="flex flex-row items-center">
{hasUppercase ? check : cross}
<span className={desc}>has uppercase</span>
</div>
<div className="flex flex-row items-center">
{hasLowercase ? check : cross}
<span className={desc}>has lowercase</span>
</div>
<div className="flex flex-row items-center">
{equals ? check : cross}
<span className={desc}>equals</span>
</div>
</div>
);
}