Skip to content

Commit 4a9c354

Browse files
committed
auth request validation rules updated
1 parent 3e526ef commit 4a9c354

2 files changed

Lines changed: 35 additions & 11 deletions

File tree

Authentication/src/Application/UseCases/Register/RequestValidator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public RegisterRequestValidator()
2121
.WithMessage("Password is required")
2222
.MinimumLength(6)
2323
.WithMessage("Password must be at least 6 characters")
24-
.MaximumLength(20)
25-
.WithMessage("Password must not exceed 20 characters");
24+
.MaximumLength(30)
25+
.WithMessage("Password must not exceed 30 characters");
2626

2727
RuleFor(x => x.Email)
2828
.NotEmpty()

BackendForFrontend/src/Features/Authentication/Register/Mediator/Validator.cs

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,42 @@ public RegisterRequestValidator()
88
{
99
RuleFor(x => x.Username)
1010
.NotEmpty()
11-
.WithMessage("Username is required.")
12-
.MinimumLength(6)
13-
.WithMessage("Username must be at least 6 characters.")
14-
.MaximumLength(20)
15-
.WithMessage("Username must be at most 20 characters.");
11+
.WithMessage("Username is required")
12+
.MinimumLength(3)
13+
.WithMessage("Username must be at least 3 characters")
14+
.MaximumLength(50)
15+
.WithMessage("Username must not exceed 50 characters")
16+
.Matches("^[a-zA-Z0-9]*$")
17+
.WithMessage("Username must contain only letters and numbers");
1618

1719
RuleFor(x => x.Password)
1820
.NotEmpty()
19-
.WithMessage("Password is required.")
21+
.WithMessage("Password is required")
2022
.MinimumLength(6)
21-
.WithMessage("Password must be at least 6 characters.")
22-
.MaximumLength(20)
23-
.WithMessage("Password must be at most 20 characters.");
23+
.WithMessage("Password must be at least 6 characters")
24+
.MaximumLength(30)
25+
.WithMessage("Password must not exceed 20 characters");
26+
27+
RuleFor(x => x.Email)
28+
.NotEmpty()
29+
.WithMessage("Email is required")
30+
.EmailAddress()
31+
.WithMessage("Email is not valid");
32+
33+
RuleFor(x => x.FirstName)
34+
.NotEmpty()
35+
.WithMessage("First name is required")
36+
.MinimumLength(2)
37+
.WithMessage("First name must be at least 2 characters")
38+
.MaximumLength(50)
39+
.WithMessage("First name must not exceed 50 characters");
40+
41+
RuleFor(x => x.LastName)
42+
.NotEmpty()
43+
.WithMessage("Last name is required")
44+
.MinimumLength(2)
45+
.WithMessage("Last name must be at least 2 characters")
46+
.MaximumLength(50)
47+
.WithMessage("Last name must not exceed 50 characters");
2448
}
2549
}

0 commit comments

Comments
 (0)