Skip to content

Commit

Permalink
security: add modify password strength constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
ZTL-UwU committed Mar 21, 2024
1 parent af91f40 commit a1f6520
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion components/ModifyPasswordDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
import { useForm } from 'vee-validate';
import { Loader2 } from 'lucide-vue-next';
import z from 'zod';
import { passwordRegex } from '~/constants';
const { $api, $toast } = useNuxtApp();
const formSchema = toTypedSchema(z.object({
oldPassword: z.string({ required_error: '请输入密码' }).min(8, { message: '用户密码长度应至少为8' }),
newPassword: z.string({ required_error: '请输入密码' }).min(8, { message: '用户密码长度应至少为8' }),
newPassword: z
.string({ required_error: '请输入密码' })
.min(8, { message: '用户密码长度应至少为8' })
.regex(passwordRegex, '密码必须包含大小写字母、数字与特殊符号'),
}));
const { handleSubmit, resetForm } = useForm({
Expand Down
7 changes: 6 additions & 1 deletion server/trpc/routers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ export const userRouter = router({
}),

modifyPassword: protectedProcedure
.input(z.object({ oldPassword: z.string(), newPassword: z.string().min(8, { message: '用户密码长度应至少为8' }) }))
.input(z.object({
oldPassword: z.string(),
newPassword: z
.string().min(8, { message: '用户密码长度应至少为8' })
.regex(passwordRegex, '密码必须包含大小写字母、数字与特殊符号'),
}))
.mutation(async ({ ctx, input }) => {
const res = await ctx.userController.modifyPassword(ctx.user, input.oldPassword, input.newPassword);
if (!res.success)
Expand Down

0 comments on commit a1f6520

Please sign in to comment.