-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from havardt/Development
Improved check efficiency
- Loading branch information
Showing
13 changed files
with
116 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
|
||
namespace EzPasswordValidator.Checks | ||
{ | ||
public static class CheckHelper | ||
{ | ||
/// <summary> | ||
/// Checks if the given string contains character repetition of length 3 or longer. | ||
/// </summary> | ||
/// <param name="expr">The expression of which filters which characters to check for repetition.</param> | ||
/// <param name="str">The string to check.</param> | ||
/// <returns> | ||
/// <c>true</c> if the given string passes the test and does NOT contain character repetition. | ||
/// If the given string does contain character repetition over the allowed length then <c>false</c> | ||
/// is returned. | ||
/// </returns> | ||
public static bool RepetitionCheck(Func<char, bool> expr, string str) | ||
{ | ||
const char baseSymbol = (char)0; | ||
char previousPrevious = baseSymbol; | ||
char previous = baseSymbol; | ||
foreach (char c in str) | ||
{ | ||
if (expr.Invoke(c)) | ||
{ | ||
if (previousPrevious == baseSymbol || previousPrevious != c) | ||
{ | ||
previousPrevious = c; | ||
} | ||
else if (previous == baseSymbol || previous != c) | ||
{ | ||
previous = c; | ||
} | ||
else | ||
{ | ||
if (previousPrevious == previous && previous == c) | ||
{ | ||
return false; | ||
} | ||
} | ||
continue; | ||
} | ||
previousPrevious = baseSymbol; | ||
previous = baseSymbol; | ||
} | ||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,6 @@ protected override bool OnExecute(string password) | |
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,6 @@ protected override bool OnExecute(string password) | |
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters