Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Haik committed Nov 9, 2023
1 parent b7e78e6 commit 5d78ae3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
9 changes: 8 additions & 1 deletion Pandatech.Crypto.Tests/PasswordTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public void Generate_ShouldReturnDifferentPasswords()
[InlineData(13, true, true, false, false)]
[InlineData(25, true, true, true, false)]
[InlineData(35, true, true, true, true)]

public void ValidationTestForGeneratedPasswords(
int length,
bool includeUppercase,
Expand All @@ -61,6 +60,7 @@ public void ValidationTestForGeneratedPasswords(
Assert.True(Password.Validate(password, length, includeUppercase, includeLowercase, includeDigits,
includeSpecialChars));
}

[Theory]
[InlineData(7, true, false, true, true)]
[InlineData(4, false, true, false, false)]
Expand All @@ -81,4 +81,11 @@ public void ValidationTestForGeneratedPasswordsOpposite(
Assert.False(Password.Validate(password, length, !includeUppercase, !includeLowercase, !includeDigits,
!includeSpecialChars));
}

[Fact]
public void PasswordValidationTests()
{
var password1 = "Qwerty123!";
Assert.True(Password.Validate(password1, 8, false, false, false, false));
}
}
4 changes: 2 additions & 2 deletions Pandatech.Crypto/Pandatech.Crypto.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>2.1.8</Version>
<Version>2.1.9</Version>
<Title>Pandatech.Crypto</Title>
<Authors>Pandatech</Authors>
<PackageIcon>pandatech.png</PackageIcon>
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<Description>PandaTech.Crypto is a .NET library simplifying common cryptograhic functions.</Description>
<RepositoryUrl>https://github.com/PandaTechAM/be-lib-pandatech-crypto</RepositoryUrl>
<PackageReleaseNotes>Changed RandomPassword to Password</PackageReleaseNotes>
<PackageReleaseNotes>Validate Password bug fix</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down
17 changes: 7 additions & 10 deletions Pandatech.Crypto/Password.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,33 +62,30 @@ public static string GenerateRandom(int length, bool includeUppercase, bool incl
return ShuffleString(password);
}

public static bool Validate(string password, int length, bool includeUppercase, bool includeLowercase,
bool includeDigits,
bool includeSpecialChars)
public static bool Validate(string password, int minLength, bool requireUppercase, bool requireLowercase,
bool requireDigits, bool requireSpecialChars)
{
if (password.Length < length)
if (password.Length < minLength)
{
return false;
}

ValidateInput(length, includeUppercase, includeLowercase, includeDigits, includeSpecialChars);

if (includeUppercase && !password.Any(char.IsUpper))
if (requireUppercase && !password.Any(char.IsUpper))
{
return false;
}

if (includeLowercase && !password.Any(char.IsLower))
if (requireLowercase && !password.Any(char.IsLower))
{
return false;
}

if (includeDigits && !password.Any(char.IsDigit))
if (requireDigits && !password.Any(char.IsDigit))
{
return false;
}

if (includeSpecialChars && !password.Any(c => SpecialChars.Contains(c)))
if (requireSpecialChars && !password.Any(c => SpecialChars.Contains(c)))
{
return false;
}
Expand Down

0 comments on commit 5d78ae3

Please sign in to comment.