Skip to content

Commit

Permalink
add common password protection to more spots
Browse files Browse the repository at this point in the history
  • Loading branch information
kentcdodds committed Mar 6, 2025
1 parent 832c24c commit 97c7611
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
9 changes: 9 additions & 0 deletions app/routes/settings+/profile.password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Button } from '#app/components/ui/button.tsx'
import { Icon } from '#app/components/ui/icon.tsx'
import { StatusButton } from '#app/components/ui/status-button.tsx'
import {
checkCommonPassword,
getPasswordHash,
requireUserId,
verifyUserPassword,
Expand Down Expand Up @@ -73,6 +74,14 @@ export async function action({ request }: Route.ActionArgs) {
message: 'Incorrect password.',
})
}
const isCommonPassword = await checkCommonPassword(newPassword)
if (isCommonPassword) {
ctx.addIssue({
path: ['newPassword'],
code: 'custom',
message: 'Password is too common',
})
}
}
},
),
Expand Down
17 changes: 15 additions & 2 deletions app/routes/settings+/profile.password_.create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { ErrorList, Field } from '#app/components/forms.tsx'
import { Button } from '#app/components/ui/button.tsx'
import { Icon } from '#app/components/ui/icon.tsx'
import { StatusButton } from '#app/components/ui/status-button.tsx'
import { getPasswordHash, requireUserId } from '#app/utils/auth.server.ts'
import {
checkCommonPassword,
getPasswordHash,
requireUserId,
} from '#app/utils/auth.server.ts'
import { prisma } from '#app/utils/db.server.ts'
import { useIsPending } from '#app/utils/misc.tsx'
import { PasswordAndConfirmPasswordSchema } from '#app/utils/user-validation.ts'
Expand Down Expand Up @@ -42,7 +46,16 @@ export async function action({ request }: Route.ActionArgs) {
const formData = await request.formData()
const submission = await parseWithZod(formData, {
async: true,
schema: CreatePasswordForm,
schema: CreatePasswordForm.superRefine(async ({ password }, ctx) => {
const isCommonPassword = await checkCommonPassword(password)
if (isCommonPassword) {
ctx.addIssue({
path: ['password'],
code: 'custom',
message: 'Password is too common',
})
}
}),
})
if (submission.status !== 'success') {
return data(
Expand Down

0 comments on commit 97c7611

Please sign in to comment.