|
1 | | -import crypto from 'node:crypto' |
2 | 1 | import { getFormProps, getInputProps, useForm } from '@conform-to/react' |
3 | 2 | import { getZodConstraint, parseWithZod } from '@conform-to/zod' |
4 | 3 | import { type SEOHandle } from '@nasa-gcn/remix-seo' |
5 | 4 | import { data, redirect, Form } from 'react-router' |
6 | 5 | import { GeneralErrorBoundary } from '#app/components/error-boundary.tsx' |
7 | 6 | import { ErrorList, Field } from '#app/components/forms.tsx' |
8 | 7 | import { StatusButton } from '#app/components/ui/status-button.tsx' |
9 | | -import { requireAnonymous, resetUserPassword } from '#app/utils/auth.server.ts' |
| 8 | +import { |
| 9 | + checkCommonPassword, |
| 10 | + requireAnonymous, |
| 11 | + resetUserPassword, |
| 12 | +} from '#app/utils/auth.server.ts' |
10 | 13 | import { useIsPending } from '#app/utils/misc.tsx' |
11 | 14 | import { PasswordAndConfirmPasswordSchema } from '#app/utils/user-validation.ts' |
12 | 15 | import { verifySessionStorage } from '#app/utils/verification.server.ts' |
@@ -44,19 +47,8 @@ export async function action({ request }: Route.ActionArgs) { |
44 | 47 | const formData = await request.formData() |
45 | 48 | const submission = await parseWithZod(formData, { |
46 | 49 | schema: ResetPasswordSchema.superRefine(async ({ password }, ctx) => { |
47 | | - const hash = crypto |
48 | | - .createHash('sha1') |
49 | | - .update(password, 'utf8') |
50 | | - .digest('hex') |
51 | | - .toUpperCase() |
52 | | - const [prefix, suffix] = [hash.slice(0, 5), hash.slice(5)] |
53 | | - const res = await fetch(`https://api.pwnedpasswords.com/range/${prefix}`) |
54 | | - if (!res.ok) throw new Error(`HTTP error! status: ${res.status}`) |
55 | | - const data = await res.text() |
56 | | - const matches = data |
57 | | - .split('/\r?\n/') |
58 | | - .filter((line) => line.includes(suffix)) |
59 | | - if (matches.length) { |
| 50 | + const isCommonPassword = await checkCommonPassword(password) |
| 51 | + if (isCommonPassword) { |
60 | 52 | ctx.addIssue({ |
61 | 53 | path: ['password'], |
62 | 54 | code: 'custom', |
|
0 commit comments