Skip to content

Commit 97c7611

Browse files
committed
add common password protection to more spots
1 parent 832c24c commit 97c7611

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

app/routes/settings+/profile.password.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Button } from '#app/components/ui/button.tsx'
88
import { Icon } from '#app/components/ui/icon.tsx'
99
import { StatusButton } from '#app/components/ui/status-button.tsx'
1010
import {
11+
checkCommonPassword,
1112
getPasswordHash,
1213
requireUserId,
1314
verifyUserPassword,
@@ -73,6 +74,14 @@ export async function action({ request }: Route.ActionArgs) {
7374
message: 'Incorrect password.',
7475
})
7576
}
77+
const isCommonPassword = await checkCommonPassword(newPassword)
78+
if (isCommonPassword) {
79+
ctx.addIssue({
80+
path: ['newPassword'],
81+
code: 'custom',
82+
message: 'Password is too common',
83+
})
84+
}
7685
}
7786
},
7887
),

app/routes/settings+/profile.password_.create.tsx

+15-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import { ErrorList, Field } from '#app/components/forms.tsx'
66
import { Button } from '#app/components/ui/button.tsx'
77
import { Icon } from '#app/components/ui/icon.tsx'
88
import { StatusButton } from '#app/components/ui/status-button.tsx'
9-
import { getPasswordHash, requireUserId } from '#app/utils/auth.server.ts'
9+
import {
10+
checkCommonPassword,
11+
getPasswordHash,
12+
requireUserId,
13+
} from '#app/utils/auth.server.ts'
1014
import { prisma } from '#app/utils/db.server.ts'
1115
import { useIsPending } from '#app/utils/misc.tsx'
1216
import { PasswordAndConfirmPasswordSchema } from '#app/utils/user-validation.ts'
@@ -42,7 +46,16 @@ export async function action({ request }: Route.ActionArgs) {
4246
const formData = await request.formData()
4347
const submission = await parseWithZod(formData, {
4448
async: true,
45-
schema: CreatePasswordForm,
49+
schema: CreatePasswordForm.superRefine(async ({ password }, ctx) => {
50+
const isCommonPassword = await checkCommonPassword(password)
51+
if (isCommonPassword) {
52+
ctx.addIssue({
53+
path: ['password'],
54+
code: 'custom',
55+
message: 'Password is too common',
56+
})
57+
}
58+
}),
4659
})
4760
if (submission.status !== 'success') {
4861
return data(

0 commit comments

Comments
 (0)