Skip to content

Commit 03b10d1

Browse files
authored
Validate password byte length (#919)
1 parent 231e707 commit 03b10d1

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

app/utils/user-validation.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ export const UsernameSchema = z
1616
export const PasswordSchema = z
1717
.string({ required_error: 'Password is required' })
1818
.min(6, { message: 'Password is too short' })
19-
// NOTE: bcrypt has a limit of 72 characters (which should be plenty long)
19+
// NOTE: bcrypt has a limit of 72 bytes (which should be plenty long)
2020
// https://github.com/epicweb-dev/epic-stack/issues/918
21-
.max(72, { message: 'Password is too long' })
21+
.refine((val) => new TextEncoder().encode(val).length <= 72, {
22+
message: 'Password is too long',
23+
})
2224

2325
export const NameSchema = z
2426
.string({ required_error: 'Name is required' })

0 commit comments

Comments
 (0)