Sprint 8 #43

Merged
csimonapastore merged 20 commits from sprints/8 into main 2025-06-21 01:11:03 +02:00
2 changed files with 6 additions and 5 deletions
Showing only changes of commit ad1909ef57 - Show all commits

View File

@@ -33,7 +33,7 @@ public class PasswordUtils_Test
Assert.IsTrue(errors.Contains(PasswordValidationEnum.MIN_NUMBER));
Assert.IsTrue(errors.Contains(PasswordValidationEnum.MIN_SPECIAL));
Assert.IsTrue(errors.Contains(PasswordValidationEnum.IDENTICAL_CHARS));
Assert.IsTrue(!errors.Contains(PasswordValidationEnum.MIN_LOWER));
Assert.IsFalse(errors.Contains(PasswordValidationEnum.MIN_LOWER));
}
catch (Exception exception)
{

View File

@@ -9,6 +9,8 @@ using BasicDotnetTemplate.MainProject.Models.Settings;
namespace BasicDotnetTemplate.MainProject.Utils;
public partial class PasswordUtils
{
protected PasswordUtils() { }
private const int MIN_LENGTH = 8;
private const int MIN_UPPER = 2;
private const int MIN_LOWER = 2;
@@ -27,14 +29,13 @@ public partial class PasswordUtils
[GeneratedRegex("[^a-zA-Z0-9]")]
private static partial Regex RegexSpecial();
[GeneratedRegex(@"(\S)\1{2,}", RegexOptions.IgnoreCase | RegexOptions.Compiled)]
private static partial Regex RegexIdenticalChars();
private static readonly Regex RegexIdenticalChars = new(@"(\S)\1{2,}", RegexOptions.IgnoreCase | RegexOptions.Compiled);
public static List<string> ValidatePassword(string password)
{
List<string> errors = [];
if (password.Length < 8)
if (password.Length < MIN_LENGTH)
errors.Add(PasswordValidationEnum.MIN_LENGTH);
if (RegexUpper().Matches(password).Count < MIN_UPPER)
@@ -49,7 +50,7 @@ public partial class PasswordUtils
if (RegexSpecial().Matches(password).Count < MIN_SPECIAL)
errors.Add(PasswordValidationEnum.MIN_SPECIAL);
if (RegexIdenticalChars().IsMatch(password))
if (RegexIdenticalChars.IsMatch(password))
errors.Add(PasswordValidationEnum.IDENTICAL_CHARS);
return errors;