Skip to content

Commit

Permalink
Improve regexp
Browse files Browse the repository at this point in the history
Avoid calling the static method at each iteration
  • Loading branch information
andreadecorte committed Oct 27, 2014
1 parent fef0b04 commit cee0e29
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion KeeStatsExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public override bool Initialize(IPluginHost host)
tsMenu.Add(m_tsSeparator);

m_tsmiStats = new ToolStripMenuItem();
m_tsmiStats.Text = "View stats...";
m_tsmiStats.Text = "&View stats...";
tsMenu.Add(m_tsmiStats);
m_tsmiStats.Click += OnMenuViewStats;

Expand Down
21 changes: 14 additions & 7 deletions StatComputer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,14 @@ public static bool ComputeStats(PwGroup group, ref List<StatItem> genericStats,
const string alphanumericOnlyPattern = "^(?=.*[A-Za-z])(?=.*[0-9])[A-Za-z0-9]+$";
const string notAlphanumericOnlyPattern = "^[^A-Za-z0-9]+$";

Dictionary<string, PwEntry> passwords = new Dictionary<string, PwEntry>();
var refRegex = new System.Text.RegularExpressions.Regex(refPattern);
var lowercaseOnlyRegex = new System.Text.RegularExpressions.Regex(lowercaseOnlyPattern);
var uppercaseOnlyRegex = new System.Text.RegularExpressions.Regex(uppercaseOnlyPattern);
var numericOnlyRegex = new System.Text.RegularExpressions.Regex(numericOnlyPattern);
var alphanumericOnlyRegex = new System.Text.RegularExpressions.Regex(alphanumericOnlyPattern);
var notAlphanumericOnlyRegex = new System.Text.RegularExpressions.Regex(notAlphanumericOnlyPattern);

var passwords = new Dictionary<string, PwEntry>();
foreach (PwEntry aPasswordObject in group.GetEntries(isRecursive)) {
try {

Expand All @@ -105,22 +112,22 @@ public static bool ComputeStats(PwGroup group, ref List<StatItem> genericStats,
emptyPasswords++;
continue;
}
if (System.Text.RegularExpressions.Regex.IsMatch(thePasswordString, refPattern)) {
if (refRegex.IsMatch(thePasswordString)) {
referencedPasswords++;
continue;
}

// quality stats on password content. Currently exlusive content. Doesn't scale currently
if (System.Text.RegularExpressions.Regex.IsMatch(thePasswordString, lowercaseOnlyPattern)) {
if (lowercaseOnlyRegex.IsMatch(thePasswordString)) {
// only lowercase
lowercaseOnlyPasswords++;
} else if (System.Text.RegularExpressions.Regex.IsMatch(thePasswordString, uppercaseOnlyPattern)) {
} else if (uppercaseOnlyRegex.IsMatch(thePasswordString)) {
uppercaseOnlyPasswords++;
} else if (System.Text.RegularExpressions.Regex.IsMatch(thePasswordString, numericOnlyPattern)) {
} else if (numericOnlyRegex.IsMatch(thePasswordString)) {
numericOnlyPasswords++;
} else if (System.Text.RegularExpressions.Regex.IsMatch(thePasswordString, alphanumericOnlyPattern)) {
} else if (alphanumericOnlyRegex.IsMatch(thePasswordString)) {
alphanumericOnlyPasswords++;
} else if (System.Text.RegularExpressions.Regex.IsMatch(thePasswordString, notAlphanumericOnlyPattern)) {
} else if (notAlphanumericOnlyRegex.IsMatch(thePasswordString)) {
notAlphanumericOnlyPasswords++;
}

Expand Down

0 comments on commit cee0e29

Please sign in to comment.