Skip to content

Commit 61bda15

Browse files
committed
Fixed letter repetition bug #20
1 parent 2130cf8 commit 61bda15

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

source/EzPasswordValidator.Tests/LetterRepetitionCheckTest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ public void WhenPasswordContainsTheSameLetterThreeTimesInARowThenPasswordIsValid
2929
Assert.IsTrue(_check.Execute(psw));
3030

3131
/// <summary> This test assumes that the default repetition length is 4. </summary>
32+
[DataRow("Aaaa@2022")]
33+
[DataRow("aaaA@2022")]
3234
[DataRow("testAAAA")]
35+
[DataRow("testAaaa")]
36+
[DataRow("testaaaA")]
37+
[DataRow("aAaatest")]
3338
[DataRow("teAAAAAst")]
3439
[DataRow("AAAAtesBBBt")]
3540
[DataRow("ØØØØtest")] //Non ISO basic latin test case

source/EzPasswordValidator/Checks/CheckHelper.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static bool RepetitionCheck(Func<char, bool> expr, string str)
4949

5050
/// <summary>
5151
/// Checks if the given string contains character repetition of the
52-
/// given length or longer.
52+
/// given length or longer (NOT case sensitive).
5353
/// </summary>
5454
/// <param name="expr">The expression of which filters which characters to check for repetition.</param>
5555
/// <param name="str">The string to check.</param>
@@ -62,13 +62,14 @@ public static bool RepetitionCheck(Func<char, bool> expr, string str)
6262
public static bool RepetitionCheck(Func<char, bool> expr, string str, int len)
6363
{
6464
int count = 1; // The current amount of repetitions.
65-
int previousChar = 0;
65+
int previousChar = char.ToLower(str[0]);
6666

67-
foreach (char c in str)
67+
foreach (char c in str.Substring(1))
6868
{
6969
if (expr.Invoke(c))
7070
{
71-
if (previousChar == c)
71+
char currentChar = char.ToLower(c);
72+
if (previousChar == currentChar)
7273
{
7374
count++;
7475
if (count == len)
@@ -78,7 +79,7 @@ public static bool RepetitionCheck(Func<char, bool> expr, string str, int len)
7879
}
7980
else
8081
{
81-
previousChar = c;
82+
previousChar = currentChar;
8283
count = 1;
8384
}
8485
}

source/EzPasswordValidator/EzPasswordValidator.csproj

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5-
<PackageLicenseUrl>https://mit-license.org/</PackageLicenseUrl>
65
<Authors>havardt</Authors>
76
<Company />
87
<PackageId>EzPasswordValidator</PackageId>
@@ -12,19 +11,18 @@
1211
<RepositoryType>git</RepositoryType>
1312
<PackageTags>Password Validator Library Checker EzPasswordValidator csharp password-validation easy</PackageTags>
1413
<SignAssembly>true</SignAssembly>
15-
<Version>2.0.0</Version>
16-
<AssemblyVersion>2.0.0.0</AssemblyVersion>
17-
<FileVersion>2.0.0.0</FileVersion>
14+
<Version>2.1.0</Version>
15+
<AssemblyVersion>2.1.0.0</AssemblyVersion>
16+
<FileVersion>2.1.0.0</FileVersion>
1817
<AssemblyOriginatorKeyFile>ezpasswordvalidator_sign_key.pfx</AssemblyOriginatorKeyFile>
1918
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
20-
<PackageReleaseNotes>**IMPORTANT** v2.0.0 is a major version change and brings some breaking changes.
19+
<PackageReleaseNotes>New in version 2.1.0:
20+
- Fixed bug in letter repetition check. The check is now case-sensitive.
2121

22-
New in this version:
23-
- Partial criteria matching
24-
- User can customize length on sequences and repetition checks
25-
- Default requirements have been updated (See docs)
26-
- Replaced some slow regex</PackageReleaseNotes>
27-
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
22+
**IMPORTANT** Upgrading from version 1.x? Version 2.x is a major version change and brings some breaking changes.
23+
</PackageReleaseNotes>
24+
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
25+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2826
</PropertyGroup>
2927

3028
</Project>

0 commit comments

Comments
 (0)