Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
DefGh committed Nov 11, 2023
2 parents c022361 + 5d78ae3 commit 35b531d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 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));
}
}
2 changes: 1 addition & 1 deletion Pandatech.Crypto/Pandatech.Crypto.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<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 35b531d

Please sign in to comment.