2015-10-01 13:38:42 +00:00
|
|
|
package matching
|
2016-01-13 22:49:04 +00:00
|
|
|
|
2015-10-01 13:38:42 +00:00
|
|
|
import (
|
2017-11-02 13:14:31 +00:00
|
|
|
"sort"
|
|
|
|
|
2015-10-07 00:14:08 +00:00
|
|
|
"github.com/nbutton23/zxcvbn-go/adjacency"
|
2016-01-13 22:49:04 +00:00
|
|
|
"github.com/nbutton23/zxcvbn-go/frequency"
|
2015-10-07 00:14:08 +00:00
|
|
|
"github.com/nbutton23/zxcvbn-go/match"
|
2015-10-01 13:38:42 +00:00
|
|
|
)
|
|
|
|
|
2015-10-05 19:56:21 +00:00
|
|
|
var (
|
2018-08-29 02:30:34 +00:00
|
|
|
dictionaryMatchers []match.Matcher
|
|
|
|
matchers []match.Matcher
|
|
|
|
adjacencyGraphs []adjacency.Graph
|
|
|
|
l33tTable adjacency.Graph
|
2015-10-14 15:38:47 +00:00
|
|
|
|
2018-08-29 02:30:34 +00:00
|
|
|
sequences map[string]string
|
2015-10-06 18:43:37 +00:00
|
|
|
)
|
2015-10-01 13:38:42 +00:00
|
|
|
|
2015-10-05 19:56:21 +00:00
|
|
|
func init() {
|
2016-01-13 22:49:04 +00:00
|
|
|
loadFrequencyList()
|
2015-10-05 19:56:21 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 02:30:34 +00:00
|
|
|
// Omnimatch runs all matchers against the password
|
2017-11-02 13:14:31 +00:00
|
|
|
func Omnimatch(password string, userInputs []string, filters ...func(match.Matcher) bool) (matches []match.Match) {
|
2015-10-06 18:43:37 +00:00
|
|
|
|
2015-12-23 21:46:05 +00:00
|
|
|
//Can I run into the issue where nil is not equal to nil?
|
2018-08-29 02:30:34 +00:00
|
|
|
if dictionaryMatchers == nil || adjacencyGraphs == nil {
|
2015-10-06 18:43:37 +00:00
|
|
|
loadFrequencyList()
|
|
|
|
}
|
2015-10-01 13:38:42 +00:00
|
|
|
|
2015-10-06 18:43:37 +00:00
|
|
|
if userInputs != nil {
|
|
|
|
userInputMatcher := buildDictMatcher("user_inputs", buildRankedDict(userInputs))
|
|
|
|
matches = userInputMatcher(password)
|
|
|
|
}
|
2015-10-01 13:38:42 +00:00
|
|
|
|
2018-08-29 02:30:34 +00:00
|
|
|
for _, matcher := range matchers {
|
2017-11-02 13:17:33 +00:00
|
|
|
shouldBeFiltered := false
|
2017-11-02 13:14:31 +00:00
|
|
|
for i := range filters {
|
|
|
|
if filters[i](matcher) {
|
2017-11-02 13:17:33 +00:00
|
|
|
shouldBeFiltered = true
|
|
|
|
break
|
2017-11-02 13:14:31 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-02 13:17:33 +00:00
|
|
|
if !shouldBeFiltered {
|
|
|
|
matches = append(matches, matcher.MatchingFunc(password)...)
|
|
|
|
}
|
2015-10-01 13:38:42 +00:00
|
|
|
}
|
2015-10-06 18:43:37 +00:00
|
|
|
sort.Sort(match.Matches(matches))
|
2015-10-01 13:38:42 +00:00
|
|
|
return matches
|
|
|
|
}
|
|
|
|
|
2015-10-06 18:43:37 +00:00
|
|
|
func loadFrequencyList() {
|
2015-10-07 00:14:08 +00:00
|
|
|
|
2018-08-29 02:30:34 +00:00
|
|
|
for n, list := range frequency.Lists {
|
|
|
|
dictionaryMatchers = append(dictionaryMatchers, match.Matcher{MatchingFunc: buildDictMatcher(n, buildRankedDict(list.List)), ID: n})
|
2015-10-07 00:14:08 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 02:30:34 +00:00
|
|
|
l33tTable = adjacency.GraphMap["l33t"]
|
2015-10-07 00:14:08 +00:00
|
|
|
|
2018-08-29 02:30:34 +00:00
|
|
|
adjacencyGraphs = append(adjacencyGraphs, adjacency.GraphMap["qwerty"])
|
|
|
|
adjacencyGraphs = append(adjacencyGraphs, adjacency.GraphMap["dvorak"])
|
|
|
|
adjacencyGraphs = append(adjacencyGraphs, adjacency.GraphMap["keypad"])
|
|
|
|
adjacencyGraphs = append(adjacencyGraphs, adjacency.GraphMap["macKeypad"])
|
2016-01-19 18:59:29 +00:00
|
|
|
|
|
|
|
//l33tFilePath, _ := filepath.Abs("adjacency/L33t.json")
|
|
|
|
//L33T_TABLE = adjacency.GetAdjancencyGraphFromFile(l33tFilePath, "l33t")
|
2015-10-14 15:38:47 +00:00
|
|
|
|
2018-08-29 02:30:34 +00:00
|
|
|
sequences = make(map[string]string)
|
|
|
|
sequences["lower"] = "abcdefghijklmnopqrstuvwxyz"
|
|
|
|
sequences["upper"] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
sequences["digits"] = "0123456789"
|
|
|
|
|
|
|
|
matchers = append(matchers, dictionaryMatchers...)
|
|
|
|
matchers = append(matchers, match.Matcher{MatchingFunc: spatialMatch, ID: spatialMatcherName})
|
|
|
|
matchers = append(matchers, match.Matcher{MatchingFunc: repeatMatch, ID: repeatMatcherName})
|
|
|
|
matchers = append(matchers, match.Matcher{MatchingFunc: sequenceMatch, ID: sequenceMatcherName})
|
|
|
|
matchers = append(matchers, match.Matcher{MatchingFunc: l33tMatch, ID: L33TMatcherName})
|
|
|
|
matchers = append(matchers, match.Matcher{MatchingFunc: dateSepMatcher, ID: dateSepMatcherName})
|
|
|
|
matchers = append(matchers, match.Matcher{MatchingFunc: dateWithoutSepMatch, ID: dateWithOutSepMatcherName})
|
2016-05-30 00:11:57 +00:00
|
|
|
|
2015-10-05 19:56:21 +00:00
|
|
|
}
|