Skip to content

Commit

Permalink
Remove length constraint from regex
Browse files Browse the repository at this point in the history
  • Loading branch information
seionmoya committed Sep 8, 2024
1 parent c51cfc8 commit e7feedd
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions Fuyu.Backend.Core/Services/AccountValidationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@ public static partial class AccountValidationService
// `(?=.*?[A-Z])`: is at least one uppercase alpha present
// `(?=.*?[a-z])`: is at least one lowercase alpha present
// `(?=.*?[0-9])`: is at least one digit present
// `{2,15}`: length must be between 2 to 15
[GeneratedRegex("^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9]).{2,15}$")]
[GeneratedRegex("^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9]).{1,}$")]
private static partial Regex UsernameRegex();

// compile-time generated regex
// `(?=.*?[A-Z])`: is at least one uppercase alpha present
// `(?=.*?[a-z])`: is at least one lowercase alpha present
// `(?=.*?[0-9])`: is at least one digit present
// `(?=.*?[#?!@$%^&*-])`: is at least one special character present
// `{8,32}`: length must be between 8 to 32
[GeneratedRegex("^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,32}$")]
[GeneratedRegex("^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{1,}$")]
private static partial Regex PasswordRegex();

public static ERegisterStatus ValidateUsername(string username)
Expand All @@ -37,7 +35,6 @@ public static ERegisterStatus ValidateUsername(string username)
return ERegisterStatus.UsernameEmpty;
}

// check character length
if (username.Length < _minUsernameLength)
{
return ERegisterStatus.UsernameTooLong;
Expand Down

0 comments on commit e7feedd

Please sign in to comment.