-
Notifications
You must be signed in to change notification settings - Fork 43
/
DefaultMatcherFactory.cs
61 lines (55 loc) · 2.51 KB
/
DefaultMatcherFactory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zxcvbn.Matcher;
namespace Zxcvbn
{
/// <summary>
/// <para>This matcher factory will use all of the default password matchers.</para>
///
/// <para>Default dictionary matchers use the built-in word lists: passwords, english, male_names, female_names, surnames</para>
/// <para>Also matching against: user data, all dictionaries with l33t substitutions</para>
/// <para>Other default matchers: repeats, sequences, digits, years, dates, spatial</para>
///
/// <para>See <see cref="IMatcher"/> and the classes that implement it for more information on each kind of pattern matcher.</para>
/// </summary>
class DefaultMatcherFactory : IMatcherFactory
{
List<IMatcher> matchers;
/// <summary>
/// Create a matcher factory that uses the default list of pattern matchers
/// </summary>
public DefaultMatcherFactory()
{
var dictionaryMatchers = new List<DictionaryMatcher>() {
new DictionaryMatcher("passwords", "passwords.lst"),
new DictionaryMatcher("english", "english.lst"),
new DictionaryMatcher("male_names", "male_names.lst"),
new DictionaryMatcher("female_names", "female_names.lst"),
new DictionaryMatcher("surnames", "surnames.lst"),
};
matchers = new List<IMatcher> {
new RepeatMatcher(),
new SequenceMatcher(),
new RegexMatcher("\\d{3,}", 10, true, "digits"),
new RegexMatcher("19\\d\\d|200\\d|201\\d", 119, false, "year"),
new DateMatcher(),
new SpatialMatcher()
};
matchers.AddRange(dictionaryMatchers);
matchers.Add(new L33tMatcher(dictionaryMatchers));
}
/// <summary>
/// Get instances of pattern matchers, adding in per-password matchers on userInputs (and userInputs with l33t substitutions)
/// </summary>
/// <param name="userInputs">Enumerable of user information</param>
/// <returns>Enumerable of matchers to use</returns>
public IEnumerable<IMatcher> CreateMatchers(IEnumerable<string> userInputs)
{
var userInputDict = new DictionaryMatcher("user_inputs", userInputs);
var leetUser = new L33tMatcher(userInputDict);
return matchers.Union(new List<IMatcher> { userInputDict, leetUser });
}
}
}