Added strong password validation
This commit is contained in:
@@ -10,12 +10,15 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.3" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.5" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="Moq" Version="4.20.72" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="3.9.1" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="3.9.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
62
MainProject.Tests/Utils/PasswordUtils_Test.cs
Normal file
62
MainProject.Tests/Utils/PasswordUtils_Test.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using BasicDotnetTemplate.MainProject.Utils;
|
||||
using BasicDotnetTemplate.MainProject.Models.Common;
|
||||
using BasicDotnetTemplate.MainProject.Enum;
|
||||
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class PasswordUtils_Test
|
||||
{
|
||||
[TestMethod]
|
||||
public void PasswordValidation_Valid()
|
||||
{
|
||||
try
|
||||
{
|
||||
List<string> errors = PasswordUtils.ValidatePassword("#aBcDeFgHi01245#");
|
||||
Assert.IsTrue(errors == null || errors.Count == 0);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Assert.Fail($"An exception was thrown: {exception}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PasswordValidation_Invalid()
|
||||
{
|
||||
try
|
||||
{
|
||||
List<string> errors = PasswordUtils.ValidatePassword("aAa1#");
|
||||
Assert.IsTrue(errors.Contains(PasswordValidationEnum.MIN_LENGTH));
|
||||
Assert.IsTrue(errors.Contains(PasswordValidationEnum.MIN_UPPER));
|
||||
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));
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Assert.Fail($"An exception was thrown: {exception}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PasswordValidation_ToLowerInvalid()
|
||||
{
|
||||
try
|
||||
{
|
||||
List<string> errors = PasswordUtils.ValidatePassword("AaBC0*TGH1#");
|
||||
Assert.IsTrue(errors.Contains(PasswordValidationEnum.MIN_LOWER));
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Assert.Fail($"An exception was thrown: {exception}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user