From 10e50eb8c76bfed9a35be4b20e85f6cca56a3ee1 Mon Sep 17 00:00:00 2001 From: Leonid Pershin Date: Thu, 2 Jul 2026 22:08:49 +0300 Subject: [PATCH] Update password validation rules and dependencies - Updated the version of the ThreeXui.Net package from 1.0.0 to 1.0.1. - Enhanced password validation in ChangePasswordCommandValidator and RegisterCommandValidator to require at least one uppercase letter and one digit, with a custom error message in Russian. - Updated the password validation in RegisterForm and ChangePasswordForm to match the new requirements, ensuring consistency across the application. --- backend/Directory.Packages.props | 2 +- .../ChangePassword/ChangePasswordCommandValidator.cs | 6 +++++- .../Auth/Register/RegisterCommandValidator.cs | 4 +++- frontend/src/features/auth/RegisterForm.tsx | 11 +++++++++-- frontend/src/features/settings/ChangePasswordForm.tsx | 5 ++++- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/backend/Directory.Packages.props b/backend/Directory.Packages.props index e4c694a..259c422 100644 --- a/backend/Directory.Packages.props +++ b/backend/Directory.Packages.props @@ -25,7 +25,7 @@ - + diff --git a/backend/src/PnvPanel.Application/Auth/ChangePassword/ChangePasswordCommandValidator.cs b/backend/src/PnvPanel.Application/Auth/ChangePassword/ChangePasswordCommandValidator.cs index d8f6acd..03d62be 100644 --- a/backend/src/PnvPanel.Application/Auth/ChangePassword/ChangePasswordCommandValidator.cs +++ b/backend/src/PnvPanel.Application/Auth/ChangePassword/ChangePasswordCommandValidator.cs @@ -7,6 +7,10 @@ public sealed class ChangePasswordCommandValidator : AbstractValidator x.CurrentPassword).NotEmpty(); - RuleFor(x => x.NewPassword).NotEmpty().MinimumLength(8); + RuleFor(x => x.NewPassword) + .NotEmpty() + .MinimumLength(8) + .Matches("^(?=.*[A-Z])(?=.*[0-9]).+$") + .WithMessage("Пароль должен содержать минимум одну заглавную букву и одну цифру."); } } diff --git a/backend/src/PnvPanel.Application/Auth/Register/RegisterCommandValidator.cs b/backend/src/PnvPanel.Application/Auth/Register/RegisterCommandValidator.cs index a763e27..af11994 100644 --- a/backend/src/PnvPanel.Application/Auth/Register/RegisterCommandValidator.cs +++ b/backend/src/PnvPanel.Application/Auth/Register/RegisterCommandValidator.cs @@ -14,6 +14,8 @@ public sealed class RegisterCommandValidator : AbstractValidator x.Password) .NotEmpty() - .MinimumLength(8); + .MinimumLength(8) + .Matches("^(?=.*[A-Z])(?=.*[0-9]).+$") + .WithMessage("Пароль должен содержать минимум одну заглавную букву и одну цифру."); } } diff --git a/frontend/src/features/auth/RegisterForm.tsx b/frontend/src/features/auth/RegisterForm.tsx index 1b2af04..16e8be9 100644 --- a/frontend/src/features/auth/RegisterForm.tsx +++ b/frontend/src/features/auth/RegisterForm.tsx @@ -15,7 +15,10 @@ const schema = z.object({ .min(3) .max(32) .regex(/^[a-zA-Z0-9_.-]+$/), - password: z.string().min(8), + password: z + .string() + .min(8) + .regex(/^(?=.*[A-Z])(?=.*[0-9]).+$/), }) type FormValues = z.infer @@ -36,7 +39,11 @@ export function RegisterForm({ onSuccess }: { onSuccess: () => void }) { onSuccess() } catch (error) { const message = - error instanceof HttpError && error.status === 409 ? t('auth.duplicateUserName') : t('auth.genericError') + error instanceof HttpError && error.status === 409 + ? t('auth.duplicateUserName') + : error instanceof HttpError + ? error.detail + : t('auth.genericError') toast.error(message) } } diff --git a/frontend/src/features/settings/ChangePasswordForm.tsx b/frontend/src/features/settings/ChangePasswordForm.tsx index 2601a7d..e2794f4 100644 --- a/frontend/src/features/settings/ChangePasswordForm.tsx +++ b/frontend/src/features/settings/ChangePasswordForm.tsx @@ -12,7 +12,10 @@ import { changePassword } from '@/features/auth/api' const schema = z.object({ currentPassword: z.string().min(1), - newPassword: z.string().min(8), + newPassword: z + .string() + .min(8) + .regex(/^(?=.*[A-Z])(?=.*[0-9]).+$/), }) type FormValues = z.infer