# The Login Authentication Model Class for ApiController

This class accepts input parameters (Login and Password) from ApiController via POST method, and do the following:

1. Trims the white spaces.
2. Checks for not null and Not Empty.
3. Checks the length of the input string to ensure it hasn't exceeded (only if the item 2 exceeds).

But, I think the class is violating the DRY Principle.

using FluentValidation;
using FluentValidation.Attributes;

{
[Validator(typeof(AuthModelValidator))]
public sealed class AuthPostModel
{
{
set { _username = value.Trim(); }
}

{
set { _password = value.Trim(); }
}
}
class AuthModelValidator : AbstractValidator<AuthPostModel>
{
public AuthModelValidator()
{

• Trim(), .NotEmpty(), Length(n, n) and When(x => !string.IsNullOrEmpty(n)) can be wrapped into something common? – Coder Absolute Nov 12 '17 at 8:27
• I don't see any DRY violations there. You do four different things on two different properties. I'd leave it as is. If you wrap it and want to define a different rule later for either property then you'll need to unwrap it agian. I find the code is fine. Although When seems to be redundant after NotEmpty that already makes sure that the exact same condition is true. – t3chb0t Nov 12 '17 at 8:33
• No, it's not redundant. If I don't add the When clause and check for non empty string then am going to get two errors if the password field is blank, for an example: 'Password' should not be empty. and 'Password' must be between 1 and 32 characters. You entered 0 characters. – Coder Absolute Nov 12 '17 at 11:02