feat: added password validation (#469)

This PR Fixes #464
This commit is contained in:
Adithya Krishna
2024-01-30 06:12:52 +05:30
committed by GitHub
parent 76c203aae6
commit 86788f4248
8 changed files with 50 additions and 18 deletions

View File

@ -1,9 +1,25 @@
import { z } from 'zod';
export const ZCurrentPasswordSchema = z
.string()
.min(6, { message: 'Must be at least 6 characters in length' })
.max(72);
export const ZPasswordSchema = z
.string()
.regex(new RegExp('.*[A-Z].*'), { message: 'One uppercase character' })
.regex(new RegExp('.*[a-z].*'), { message: 'One lowercase character' })
.regex(new RegExp('.*\\d.*'), { message: 'One number' })
.regex(new RegExp('.*[`~<>?,./!@#$%^&*()\\-_+="\'|{}\\[\\];:\\\\].*'), {
message: 'One special character is required',
})
.min(8, { message: 'Must be at least 8 characters in length' })
.max(72, { message: 'Cannot be more than 72 characters in length' });
export const ZSignUpMutationSchema = z.object({
name: z.string().min(1),
email: z.string().email(),
password: z.string().min(6),
password: ZPasswordSchema,
signature: z.string().min(1, { message: 'A signature is required.' }),
});

View File

@ -1,5 +1,7 @@
import { z } from 'zod';
import { ZCurrentPasswordSchema, ZPasswordSchema } from '../auth-router/schema';
export const ZRetrieveUserByIdQuerySchema = z.object({
id: z.number().min(1),
});
@ -10,8 +12,8 @@ export const ZUpdateProfileMutationSchema = z.object({
});
export const ZUpdatePasswordMutationSchema = z.object({
currentPassword: z.string().min(6),
password: z.string().min(6),
currentPassword: ZCurrentPasswordSchema,
password: ZPasswordSchema,
});
export const ZForgotPasswordFormSchema = z.object({
@ -19,7 +21,7 @@ export const ZForgotPasswordFormSchema = z.object({
});
export const ZResetPasswordFormSchema = z.object({
password: z.string().min(6),
password: ZPasswordSchema,
token: z.string().min(1),
});

View File

@ -1,4 +1,4 @@
import { Table } from '@tanstack/react-table';
import type { Table } from '@tanstack/react-table';
import { ChevronLeft, ChevronRight, ChevronsLeft, ChevronsRight } from 'lucide-react';
import { match } from 'ts-pattern';