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.
This commit is contained in:
@@ -25,7 +25,7 @@
|
|||||||
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.9" />
|
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.9" />
|
||||||
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="8.19.1" />
|
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="8.19.1" />
|
||||||
<PackageVersion Include="Telegram.Bot" Version="22.10.1" />
|
<PackageVersion Include="Telegram.Bot" Version="22.10.1" />
|
||||||
<PackageVersion Include="ThreeXui.Net" Version="1.0.0" />
|
<PackageVersion Include="ThreeXui.Net" Version="1.0.1" />
|
||||||
<!-- Тестирование (M8) -->
|
<!-- Тестирование (M8) -->
|
||||||
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||||
<PackageVersion Include="xunit" Version="2.9.3" />
|
<PackageVersion Include="xunit" Version="2.9.3" />
|
||||||
|
|||||||
+5
-1
@@ -7,6 +7,10 @@ public sealed class ChangePasswordCommandValidator : AbstractValidator<ChangePas
|
|||||||
public ChangePasswordCommandValidator()
|
public ChangePasswordCommandValidator()
|
||||||
{
|
{
|
||||||
RuleFor(x => x.CurrentPassword).NotEmpty();
|
RuleFor(x => x.CurrentPassword).NotEmpty();
|
||||||
RuleFor(x => x.NewPassword).NotEmpty().MinimumLength(8);
|
RuleFor(x => x.NewPassword)
|
||||||
|
.NotEmpty()
|
||||||
|
.MinimumLength(8)
|
||||||
|
.Matches("^(?=.*[A-Z])(?=.*[0-9]).+$")
|
||||||
|
.WithMessage("Пароль должен содержать минимум одну заглавную букву и одну цифру.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ public sealed class RegisterCommandValidator : AbstractValidator<RegisterCommand
|
|||||||
|
|
||||||
RuleFor(x => x.Password)
|
RuleFor(x => x.Password)
|
||||||
.NotEmpty()
|
.NotEmpty()
|
||||||
.MinimumLength(8);
|
.MinimumLength(8)
|
||||||
|
.Matches("^(?=.*[A-Z])(?=.*[0-9]).+$")
|
||||||
|
.WithMessage("Пароль должен содержать минимум одну заглавную букву и одну цифру.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,10 @@ const schema = z.object({
|
|||||||
.min(3)
|
.min(3)
|
||||||
.max(32)
|
.max(32)
|
||||||
.regex(/^[a-zA-Z0-9_.-]+$/),
|
.regex(/^[a-zA-Z0-9_.-]+$/),
|
||||||
password: z.string().min(8),
|
password: z
|
||||||
|
.string()
|
||||||
|
.min(8)
|
||||||
|
.regex(/^(?=.*[A-Z])(?=.*[0-9]).+$/),
|
||||||
})
|
})
|
||||||
|
|
||||||
type FormValues = z.infer<typeof schema>
|
type FormValues = z.infer<typeof schema>
|
||||||
@@ -36,7 +39,11 @@ export function RegisterForm({ onSuccess }: { onSuccess: () => void }) {
|
|||||||
onSuccess()
|
onSuccess()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message =
|
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)
|
toast.error(message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,10 @@ import { changePassword } from '@/features/auth/api'
|
|||||||
|
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
currentPassword: z.string().min(1),
|
currentPassword: z.string().min(1),
|
||||||
newPassword: z.string().min(8),
|
newPassword: z
|
||||||
|
.string()
|
||||||
|
.min(8)
|
||||||
|
.regex(/^(?=.*[A-Z])(?=.*[0-9]).+$/),
|
||||||
})
|
})
|
||||||
|
|
||||||
type FormValues = z.infer<typeof schema>
|
type FormValues = z.infer<typeof schema>
|
||||||
|
|||||||
Reference in New Issue
Block a user