Mizuki/Validators/PasswordChangeValidator.cs
2025-01-15 21:13:51 +01:00

31 lines
No EOL
791 B
C#

using FluentValidation;
using Mizuki.Dtos;
namespace Mizuki.Validators;
/// <summary>
/// The data validator for the PasswordChangeDto.
/// </summary>
public class PasswordChangeValidator : AbstractValidator<PasswordChangeDto>
{
/// <summary>
/// Constructs the ruleset for the PasswordChangeValidator.
/// </summary>
public PasswordChangeValidator()
{
RuleFor(x => x.OldPassword)
.NotEmpty();
RuleFor(x => x.OldPassword)
.MinimumLength(8);
RuleFor(x => x.NewPassword)
.NotEmpty();
RuleFor(x => x.NewPassword)
.MinimumLength(8);
RuleFor(x => x.NewPassword)
.Matches(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@#$%^&*!])[A-Za-z\d@#$%^&*!]{8,}$");
}
}