Debian Codegraph @

matching/leet.go

raw symbols SCIP
1 package matchingscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/
2
3 import (
4 "stringsscip-go gomod github.com/golang/go/src go1.20 strings/"
5
6 "github.com/ccojocar/zxcvbn-go/entropyscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/entropy`/"
7 "github.com/ccojocar/zxcvbn-go/matchscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/match`/"
8 )
9
10 // L33TMatcherName id
11 const L33TMatcherNamescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/L33TMatcherName. = "l33t"
12
13 // FilterL33tMatcher can be pass to zxcvbn-go.PasswordStrength to skip that matcher
14 func FilterL33tMatcherscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/FilterL33tMatcher().(m matchscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/match`/.Matcherscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/match`/Matcher#) bool {
15 return m.IDscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/match`/Matcher#ID. == L33TMatcherNamescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/L33TMatcherName.
16 }
17
18 func l33tMatchscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/l33tMatch().(password string) []matchscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/match`/.Matchscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/match`/Match# {
19 permutations := getPermutationsscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/getPermutations().(password)
20
21 var matches []matchscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/match`/.Matchscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/match`/Match#
22
23 for _, permutation := range permutations {
24 for _, mather := range dictionaryMatchersscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/dictionaryMatchers. {
25 matches = append(matches, mather.MatchingFuncscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/match`/Matcher#MatchingFunc.(permutation)...)
26 }
27 }
28
29 for _, match := range matches {
30 match.Entropyscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/match`/Match#Entropy. += entropyscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/entropy`/.ExtraLeetEntropyscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/entropy`/ExtraLeetEntropy().(match, password)
31 match.DictionaryNamescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/match`/Match#DictionaryName. = match.DictionaryNamescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/match`/Match#DictionaryName. + "_3117"
32 }
33
34 return matches
35 }
36
37 // This function creates a list of permutations based on a fixed table stored on data. The table
38 // will be reduced in order to proceed in the function using only relevant values (see
39 // relevantL33tSubtable).
40 func getPermutationsscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/getPermutations().(password string) []string {
41 substitutions := relevantL33tSubtablescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/relevantL33tSubtable().(password)
42 permutations := getAllPermutationsOfLeetSubstitutionsscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/getAllPermutationsOfLeetSubstitutions().(password, substitutions)
43 return permutations
44 }
45
46 // This function loads the table from data but only keep in memory the values that are present
47 // inside the provided password.
48 func relevantL33tSubtablescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/relevantL33tSubtable().(password string) map[string][]string {
49 relevantSubs := make(map[string][]string)
50 for key, values := range l33tTablescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/l33tTable..Graphscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/adjacency`/Graph#Graph. {
51 for _, value := range values {
52 if stringsscip-go gomod github.com/golang/go/src go1.20 strings/.Containsscip-go gomod github.com/golang/go/src go1.20 strings/Contains().(password, value) {
53 relevantSubs[key] = append(relevantSubs[key], value)
54 }
55 }
56 }
57
58 return relevantSubs
59 }
60
61 // This function creates the list of permutations of a given password using the provided table as
62 // reference for its operation.
63 func getAllPermutationsOfLeetSubstitutionsscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/getAllPermutationsOfLeetSubstitutions().(password string, table map[string][]string) []string {
64 result := []string{}
65
66 // create a list of tables without conflicting keys/values (this happens for "|", "7" and "1")
67 noConflictsTables := createListOfMapsWithoutConflictsscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/createListOfMapsWithoutConflicts().(table)
68 for _, noConflictsTable := range noConflictsTables {
69 substitutionsMaps := createSubstitutionsMapsFromTablescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/createSubstitutionsMapsFromTable().(noConflictsTable)
70 for _, substitutionsMap := range substitutionsMaps {
71 newValue := createWordForSubstitutionMapscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/createWordForSubstitutionMap().(password, substitutionsMap)
72 if !stringSliceContainsValuescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/stringSliceContainsValue().(result, newValue) {
73 result = append(result, newValue)
74 }
75 }
76 }
77
78 return result
79 }
80
81 // Create the possible list of maps removing the conflicts from it. As an example, the value "|"
82 // may represent "i" and "l". For each representation of the conflicting value, a new map is
83 // created. This may grow exponencialy according to the number of conflicts. The number of maps
84 // returned by this function may be reduced if the relevantL33tSubtable function was called to
85 // identify only relevant items.
86 func createListOfMapsWithoutConflictsscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/createListOfMapsWithoutConflicts().(table map[string][]string) []map[string][]string {
87 // the resulting list starts with the provided table
88 result := []map[string][]string{}
89 result = append(result, table)
90
91 // iterate over the list of conflicts in order to expand the maps for each one
92 conflicts := retrieveConflictsListFromTablescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/retrieveConflictsListFromTable().(table)
93 for _, value := range conflicts {
94 newMapList := []map[string][]string{}
95
96 // for each conflict a new list of maps will be created for every already known map
97 for _, currentMap := range result {
98 newMaps := createDifferentMapsForLeetCharscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/createDifferentMapsForLeetChar().(currentMap, value)
99 newMapList = append(newMapList, newMaps...)
100 }
101
102 result = newMapList
103 }
104
105 return result
106 }
107
108 // This function retrieves the list of values that appear for one or more keys. This is useful to
109 // know which l33t chars can represent more than one letter.
110 func retrieveConflictsListFromTablescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/retrieveConflictsListFromTable().(table map[string][]string) []string {
111 result := []string{}
112 foundValues := []string{}
113
114 for _, values := range table {
115 for _, value := range values {
116 if stringSliceContainsValuescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/stringSliceContainsValue().(foundValues, value) {
117 // only add on results if it was not identified as conflict before
118 if !stringSliceContainsValuescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/stringSliceContainsValue().(result, value) {
119 result = append(result, value)
120 }
121 } else {
122 foundValues = append(foundValues, value)
123 }
124 }
125 }
126
127 return result
128 }
129
130 // This function aims to create different maps for a given char if this char represents a conflict.
131 // If the specified char is not a conflict one, the same map will be returned. In scenarios which
132 // the provided char can not be found on map, an empty list will be returned. This function was
133 // designed to be used on conflicts situations.
134 func createDifferentMapsForLeetCharscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/createDifferentMapsForLeetChar().(table map[string][]string, leetChar string) []map[string][]string {
135 result := []map[string][]string{}
136
137 keysWithSameValue := retrieveListOfKeysWithSpecificValueFromTablescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/retrieveListOfKeysWithSpecificValueFromTable().(table, leetChar)
138 for _, key := range keysWithSameValue {
139 newMap := copyMapRemovingSameValueFromOtherKeysscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/copyMapRemovingSameValueFromOtherKeys().(table, key, leetChar)
140 result = append(result, newMap)
141 }
142
143 return result
144 }
145
146 // This function retrieves the list of keys that can be represented using the given value.
147 func retrieveListOfKeysWithSpecificValueFromTablescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/retrieveListOfKeysWithSpecificValueFromTable().(table map[string][]string, valueToFind string) []string {
148 result := []string{}
149
150 for key, values := range table {
151 for _, value := range values {
152 if value == valueToFind && !stringSliceContainsValuescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/stringSliceContainsValue().(result, key) {
153 result = append(result, key)
154 }
155 }
156 }
157
158 return result
159 }
160
161 // This function returns a list of substitution map from a given table. Each map in the result will
162 // provide only one representation for each value. As an example, if the provided map contains the
163 // values "@" and "4" in the possibilities to represent "a", two maps will be created where one
164 // will contain "a" mapping to "@" and the other one will provide "a" mapping to "4".
165 func createSubstitutionsMapsFromTablescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/createSubstitutionsMapsFromTable().(table map[string][]string) []map[string]string {
166 result := []map[string]string{{"": ""}}
167
168 for key, values := range table {
169 newResult := []map[string]string{}
170
171 for _, mapInCurrentResult := range result {
172 for _, value := range values {
173 newMapForValue := copyMapscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/copyMap().(mapInCurrentResult)
174 newMapForValue[key] = value
175 newResult = append(newResult, newMapForValue)
176 }
177 }
178
179 result = newResult
180 }
181
182 // verification to make sure that the slice was filled
183 if len(result) == 1 && len(result[0]) == 1 && result[0][""] == "" {
184 return []map[string]string{}
185 }
186
187 return result
188 }
189
190 // This function replaces the values provided on substitution map over the provided word.
191 func createWordForSubstitutionMapscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/createWordForSubstitutionMap().(word string, substitutionMap map[string]string) string {
192 result := word
193 for key, value := range substitutionMap {
194 result = stringsscip-go gomod github.com/golang/go/src go1.20 strings/.ReplaceAllscip-go gomod github.com/golang/go/src go1.20 strings/ReplaceAll().(result, value, key)
195 }
196
197 return result
198 }
199
200 func stringSliceContainsValuescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/stringSliceContainsValue().(slice []string, value string) bool {
201 for _, valueInSlice := range slice {
202 if valueInSlice == value {
203 return true
204 }
205 }
206
207 return false
208 }
209
210 func copyMapscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/copyMap().(table map[string]string) map[string]string {
211 result := make(map[string]string)
212
213 for key, value := range table {
214 result[key] = value
215 }
216
217 return result
218 }
219
220 // This function creates a new map based on the one provided but excluding possible representations
221 // of the same value on other keys.
222 func copyMapRemovingSameValueFromOtherKeysscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/copyMapRemovingSameValueFromOtherKeys().(table map[string][]string, keyToFix string, valueToFix string) map[string][]string {
223 result := make(map[string][]string)
224
225 for key, values := range table {
226 for _, value := range values {
227 if value != valueToFix || key == keyToFix {
228 result[key] = append(result[key], value)
229 }
230 }
231 }
232
233 return result
234 }