Skip to content

Commit

Permalink
Merge pull request #80 from REAN-Foundation/password_validation_fixes
Browse files Browse the repository at this point in the history
Password validation fixes
  • Loading branch information
dattatraya-inflection authored Oct 10, 2024
2 parents a4c22d5 + e71ce9c commit 37a2b44
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
phone: z.string().optional(),
resetCode: z.string().min(6, { message: 'Reset code must be 6 characters' }),
newPassword: z.string().regex(
/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]+$/,
/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[@$!%*?&#])[A-Za-z\d@$!%*?&#]+$/,
{
message: 'Password should contain at least 1 capital letter, 1 small letter, 1 digit, and 1 special character.'
}
Expand All @@ -91,7 +91,7 @@
}
),
confirmPassword: z.string().regex(
/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]+$/,
/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[@$!%*?&#])[A-Za-z\d@$!%*?&#]+$/,
{
message: 'Password should contain at least 1 capital letter, 1 small letter, 1 digit, and 1 special character.'
}
Expand Down Expand Up @@ -160,7 +160,11 @@
toast.error(res.Message);
}
} catch (err) {
toast.error('Data validation error');
if (err instanceof z.ZodError) {
errors = err.flatten().fieldErrors;
} else {
toast.error('An unexpected error occurred');
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/api/server/symptoms/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const DELETE = async (event: RequestEvent) => {
);
}
throw redirect(
successMessage(response.Message),
successMessage(`Symptom deleted successfully!`),
event
);
};
4 changes: 2 additions & 2 deletions src/routes/users/[userId]/change-password/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const changePasswordSchema = zfd
// newPassword: z.string().min(8, "New password should be greater than 8 characters"),
// confirmNewPassword: z.string().min(1, "Please confirm the new password"),
newPassword: z.string().regex(
/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]+$/,
/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[@$!%*?&#])[A-Za-z\d@$!%*?&#]+$/,
{
message: 'Password should contain at least 1 capital letter, 1 small letter, 1 digit, and 1 special character.'
}
Expand All @@ -24,7 +24,7 @@ const changePasswordSchema = zfd
}
),
confirmNewPassword: z.string().regex(
/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]+$/,
/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[@$!%*?&#])[A-Za-z\d@$!%*?&#]+$/,
{
message: 'Password should contain at least 1 capital letter, 1 small letter, 1 digit, and 1 special character.'
}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/users/[userId]/users/create/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const createUserSchema = zfd.formData({
}
),
password: z.string().regex(
/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]+$/,
/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[@$!%*?&#])[A-Za-z\d@$!%*?&#]+$/,
{
message: 'Password should contain at least 1 capital letter , 1 digit & 1 special character'
}
Expand Down

0 comments on commit 37a2b44

Please sign in to comment.