| import { z } from 'zod';
|
|
|
| |
| |
| |
|
|
| export const passwordValidation = {
|
| minLength: 8,
|
| pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d@$!%*?&]{8,}$/,
|
| messages: {
|
| required: 'auth.signIn.validation.passwordRequired',
|
| minLength: 'auth.signIn.validation.passwordMinLength',
|
| pattern: 'auth.signIn.validation.passwordPattern',
|
| },
|
| };
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| export const validatePassword = (password: string, t: (key: string) => string) => {
|
| if (!password) {
|
| return t(passwordValidation.messages.required);
|
| }
|
|
|
| if (password.length < passwordValidation.minLength) {
|
| return t(passwordValidation.messages.minLength);
|
| }
|
|
|
| if (!passwordValidation.pattern.test(password)) {
|
| return t(passwordValidation.messages.pattern);
|
| }
|
|
|
| return null;
|
| };
|
|
|
| |
| |
|
|
| export const passwordSchema = (t: (key: string) => string) =>
|
| z
|
| .string()
|
| .min(1, { message: t(passwordValidation.messages.required) })
|
| .min(passwordValidation.minLength, {
|
| message: t(passwordValidation.messages.minLength),
|
| });
|
|
|
|
|
|
|
|
|
|
|
| |
| |
|
|
| export const passwordConfirmationSchema = (t: (key: string) => string) =>
|
| z
|
| .object({
|
| password: passwordSchema(t),
|
| confirmPassword: z.string(),
|
| })
|
| .refine((data) => data.password === data.confirmPassword, {
|
| message: t('users.validation.passwordsNotMatch'),
|
| path: ['confirmPassword'],
|
| });
|
|
|