refactor: implement password validation in dto; remove redundant validation code in auth controller

This commit is contained in:
2026-01-06 14:44:29 -05:00
parent 21b6f95edc
commit 73b847c06b
2 changed files with 4 additions and 30 deletions
@@ -23,6 +23,8 @@ namespace SharpbinV3.Server.DTOs
var results = new List<ValidationResult>();
if (!ValidateUsername().IsMatch(Username))
results.Add(new ValidationResult("Username can only contain letters, numbers, underscores, and dots.", [nameof(Username)]));
if (!ValidatePassword().IsMatch(Password))
results.Add(new ValidationResult("Password should have at least 8 characters, including uppercase, lowercase, and digits.", [nameof(Password)]));
if (DisplayName != null)
{
@@ -42,5 +44,7 @@ namespace SharpbinV3.Server.DTOs
[GeneratedRegex("^[A-Za-z0-9_.]+$")]
private static partial Regex ValidateUsername();
[GeneratedRegex("^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d).{8,}$")]
public static partial Regex ValidatePassword();
}
}