Browse Source

Improvements to username and password validations (#1745)

* Fix: Improve special character regex (#1744)
* update password special character regex to support
( `-` `_` `=` `+` `[` `]` `;` `'` `\` `/` )

* Fix: Allow usernames starting from 2 characters (#1744)
* update username validation to support short usernames starting from 2 characters

* remove char validation altogether

---------

Co-authored-by: Bernd Storath <[email protected]>
pull/1778/head
Pokydko Oleksandr 4 days ago
committed by GitHub
parent
commit
940edb2b0c
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      src/i18n/locales/en.json
  2. 6
      src/server/database/repositories/user/types.ts

4
src/i18n/locales/en.json

@ -189,10 +189,6 @@
"user": {
"username": "Username",
"password": "Password",
"passwordUppercase": "Password must have at least 1 uppercase letter",
"passwordLowercase": "Password must have at least 1 lowercase letter",
"passwordNumber": "Password must have at least 1 number",
"passwordSpecial": "Password must have at least 1 special character",
"remember": "Remember",
"name": "Name",
"email": "Email",

6
src/server/database/repositories/user/types.ts

@ -6,16 +6,12 @@ export type UserType = InferSelectModel<typeof user>;
const username = z
.string({ message: t('zod.user.username') })
.min(8, t('zod.user.username'))
.min(2, t('zod.user.username'))
.pipe(safeStringRefine);
const password = z
.string({ message: t('zod.user.password') })
.min(12, t('zod.user.password'))
.regex(/[A-Z]/, t('zod.user.passwordUppercase'))
.regex(/[a-z]/, t('zod.user.passwordLowercase'))
.regex(/\d/, t('zod.user.passwordNumber'))
.regex(/[!@#$%^&*(),.?":{}|<>]/, t('zod.user.passwordSpecial'))
.pipe(safeStringRefine);
const remember = z.boolean({ message: t('zod.user.remember') });

Loading…
Cancel
Save