Added data binding. Moved all the Json files into on folder
This commit is contained in:
parent
17f81ad607
commit
80ad1b1d96
|
@ -2,9 +2,8 @@ package adjacency
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
|
||||||
// "fmt"
|
// "fmt"
|
||||||
"path/filepath"
|
"github.com/nbutton23/zxcvbn-go/data"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,35 +14,49 @@ type AdjacencyGraph struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var AdjacencyGph = make(map[string]AdjacencyGraph);
|
||||||
|
func init() {
|
||||||
|
//todo get currentloc so that i don't have to know the whole path
|
||||||
|
log.SetFlags(log.Lshortfile)
|
||||||
|
AdjacencyGph["qwerty"] = buildQwerty()
|
||||||
|
AdjacencyGph["dvorak"] = buildDvorak()
|
||||||
|
AdjacencyGph["keypad"] = buildKeypad()
|
||||||
|
AdjacencyGph["macKeypad"] = buildMacKeypad()
|
||||||
|
}
|
||||||
|
|
||||||
func buildQwerty() AdjacencyGraph {
|
func buildQwerty() AdjacencyGraph {
|
||||||
filePath, _ := filepath.Abs("Qwerty.json")
|
data, err := zxcvbn_data.Asset("data/Qwerty.json")
|
||||||
return GetAdjancencyGraphFromFile(filePath, "qwerty")
|
if err != nil {
|
||||||
|
panic("Can't find asset")
|
||||||
|
}
|
||||||
|
return GetAdjancencyGraphFromFile(data, "qwerty")
|
||||||
}
|
}
|
||||||
func buildDvorak() AdjacencyGraph {
|
func buildDvorak() AdjacencyGraph {
|
||||||
filePath, _ := filepath.Abs("Dvorak.json")
|
data, err := zxcvbn_data.Asset("data/Dvorak.json")
|
||||||
return GetAdjancencyGraphFromFile(filePath, "dvorak")
|
if err != nil {
|
||||||
|
panic("Can't find asset")
|
||||||
|
}
|
||||||
|
return GetAdjancencyGraphFromFile(data, "dvorak")
|
||||||
}
|
}
|
||||||
func buildKeypad() AdjacencyGraph {
|
func buildKeypad() AdjacencyGraph {
|
||||||
filePath, _ := filepath.Abs("Keypad.json")
|
data, err := zxcvbn_data.Asset("data/Keypad.json")
|
||||||
return GetAdjancencyGraphFromFile(filePath, "keypad")
|
if err != nil {
|
||||||
|
panic("Can't find asset")
|
||||||
|
}
|
||||||
|
return GetAdjancencyGraphFromFile(data, "keypad")
|
||||||
}
|
}
|
||||||
func buildMacKeypad() AdjacencyGraph {
|
func buildMacKeypad() AdjacencyGraph {
|
||||||
filePath, _ := filepath.Abs("MacKeypad.json")
|
data, err := zxcvbn_data.Asset("data/MacKeypad.json")
|
||||||
return GetAdjancencyGraphFromFile(filePath, "mac_keypad")
|
if err != nil {
|
||||||
|
panic("Can't find asset")
|
||||||
|
}
|
||||||
|
return GetAdjancencyGraphFromFile(data, "mac_keypad")
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAdjancencyGraphFromFile(filePath string, name string) AdjacencyGraph {
|
func GetAdjancencyGraphFromFile(data []byte, name string) AdjacencyGraph {
|
||||||
data, err := ioutil.ReadFile(filePath)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var graph AdjacencyGraph;
|
var graph AdjacencyGraph;
|
||||||
err = json.Unmarshal(data, &graph)
|
err := json.Unmarshal(data, &graph)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,26 +1,45 @@
|
||||||
package frequency
|
package frequency
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"github.com/nbutton23/zxcvbn-go/data"
|
||||||
)
|
)
|
||||||
|
|
||||||
type listWrapper struct {
|
type FrequencyList struct {
|
||||||
|
Name string
|
||||||
List []string
|
List []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetStringListFromFile(filePath string) []string {
|
var FrequencyLists = make(map[string]FrequencyList)
|
||||||
data, err := ioutil.ReadFile(filePath)
|
func init() {
|
||||||
|
maleFilePath := getAsset("data/MaleNames.json")
|
||||||
|
femaleFilePath := getAsset("data/FemaleNames.json")
|
||||||
|
surnameFilePath := getAsset("data/Surnames.json")
|
||||||
|
englishFilePath := getAsset("data/English.json")
|
||||||
|
passwordsFilePath := getAsset("data/Passwords.json")
|
||||||
|
|
||||||
|
FrequencyLists["MaleNames"] = GetStringListFromAsset(maleFilePath, "MaleNames")
|
||||||
|
FrequencyLists["FemaleNames"] = GetStringListFromAsset(femaleFilePath, "FemaleNames")
|
||||||
|
FrequencyLists["Surname"] = GetStringListFromAsset(surnameFilePath, "Surname")
|
||||||
|
FrequencyLists["English"] = GetStringListFromAsset(englishFilePath, "English")
|
||||||
|
FrequencyLists["Passwords"] = GetStringListFromAsset(passwordsFilePath, "Passwords")
|
||||||
|
|
||||||
|
}
|
||||||
|
func getAsset(name string) []byte {
|
||||||
|
data, err := zxcvbn_data.Asset(name)
|
||||||
|
if err != nil {
|
||||||
|
panic("Error getting asset " + name)
|
||||||
|
}
|
||||||
|
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
func GetStringListFromAsset(data []byte, name string) FrequencyList {
|
||||||
|
|
||||||
|
var tempList FrequencyList;
|
||||||
|
err := json.Unmarshal(data, &tempList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
tempList.Name = name
|
||||||
|
return tempList
|
||||||
var tempList listWrapper;
|
|
||||||
err = json.Unmarshal(data, &tempList)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
return tempList.List
|
|
||||||
}
|
}
|
|
@ -3,10 +3,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"zxcvbn-go/frequency"
|
"github.com/nbutton23/zxcvbn-go/frequency"
|
||||||
"path/filepath"
|
"github.com/nbutton23/zxcvbn-go/adjacency"
|
||||||
"zxcvbn-go/adjacency"
|
"github.com/nbutton23/zxcvbn-go/match"
|
||||||
"zxcvbn-go/match"
|
|
||||||
"sort"
|
"sort"
|
||||||
// "github.com/deckarep/golang-set"
|
// "github.com/deckarep/golang-set"
|
||||||
)
|
)
|
||||||
|
@ -53,39 +52,23 @@ func Omnimatch(password string, userInputs []string) (matches []match.Match) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadFrequencyList() {
|
func loadFrequencyList() {
|
||||||
maleFilePath, _ := filepath.Abs("frequency/MaleNames.json")
|
|
||||||
femaleFilePath, _ := filepath.Abs("frequency/FemaleNames.json")
|
|
||||||
surnameFilePath, _ := filepath.Abs("frequency/Surnames.json")
|
|
||||||
englishFilePath, _ := filepath.Abs("frequency/English.json")
|
|
||||||
passwordsFilePath, _ := filepath.Abs("frequency/Passwords.json")
|
|
||||||
|
|
||||||
DICTIONARY_MATCHERS = append(DICTIONARY_MATCHERS, buildDictMatcher("MaleNames", buildRankedDict(frequency.GetStringListFromFile(maleFilePath))))
|
for n, list := range frequency.FrequencyLists {
|
||||||
DICTIONARY_MATCHERS = append(DICTIONARY_MATCHERS, buildDictMatcher("FemaleNames", buildRankedDict(frequency.GetStringListFromFile(femaleFilePath))))
|
DICTIONARY_MATCHERS = append(DICTIONARY_MATCHERS,buildDictMatcher(n, buildRankedDict(list.List)))
|
||||||
DICTIONARY_MATCHERS = append(DICTIONARY_MATCHERS, buildDictMatcher("Surnames", buildRankedDict(frequency.GetStringListFromFile(surnameFilePath))))
|
}
|
||||||
DICTIONARY_MATCHERS = append(DICTIONARY_MATCHERS, buildDictMatcher("English", buildRankedDict(frequency.GetStringListFromFile(englishFilePath))))
|
|
||||||
DICTIONARY_MATCHERS = append(DICTIONARY_MATCHERS, buildDictMatcher("Passwords", buildRankedDict(frequency.GetStringListFromFile(passwordsFilePath))))
|
|
||||||
|
|
||||||
qwertyfilePath, _ := filepath.Abs("adjacency/Qwerty.json")
|
KEYBOARD_AVG_DEGREE = adjacency.AdjacencyGph["querty"].CalculateAvgDegree()
|
||||||
dvorakfilePath, _ := filepath.Abs("adjacency/Dvorak.json")
|
KEYBOARD_STARTING_POSITIONS = len(adjacency.AdjacencyGph["querty"].Graph)
|
||||||
keypadfilePath, _ := filepath.Abs("adjacency/Keypad.json")
|
KEYPAD_AVG_DEGREE = adjacency.AdjacencyGph["keypad"].CalculateAvgDegree()
|
||||||
macKeypadfilePath, _ := filepath.Abs("adjacency/MacKeypad.json")
|
KEYPAD_STARTING_POSITIONS = len(adjacency.AdjacencyGph["keypad"].Graph)
|
||||||
|
|
||||||
qwertGraph := adjacency.GetAdjancencyGraphFromFile(qwertyfilePath, "qwert")
|
ADJACENCY_GRAPHS = append(ADJACENCY_GRAPHS, adjacency.AdjacencyGph["querty"])
|
||||||
keypadGraph := adjacency.GetAdjancencyGraphFromFile(keypadfilePath, "keypad")
|
ADJACENCY_GRAPHS = append(ADJACENCY_GRAPHS, adjacency.AdjacencyGph["dvorak"])
|
||||||
|
ADJACENCY_GRAPHS = append(ADJACENCY_GRAPHS, adjacency.AdjacencyGph["keypad"])
|
||||||
|
ADJACENCY_GRAPHS = append(ADJACENCY_GRAPHS, adjacency.AdjacencyGph["macKeypad"])
|
||||||
KEYBOARD_AVG_DEGREE = qwertGraph.CalculateAvgDegree()
|
//
|
||||||
KEYBOARD_STARTING_POSITIONS = len(qwertGraph.Graph)
|
// l33tFilePath, _ := filepath.Abs("adjacency/L33t.json")
|
||||||
KEYPAD_AVG_DEGREE = keypadGraph.CalculateAvgDegree()
|
// L33T_TABLE = adjacency.GetAdjancencyGraphFromFile(l33tFilePath, "l33t")
|
||||||
KEYPAD_STARTING_POSITIONS = len(keypadGraph.Graph)
|
|
||||||
|
|
||||||
ADJACENCY_GRAPHS = append(ADJACENCY_GRAPHS, qwertGraph)
|
|
||||||
ADJACENCY_GRAPHS = append(ADJACENCY_GRAPHS, adjacency.GetAdjancencyGraphFromFile(dvorakfilePath, "dvorak"))
|
|
||||||
ADJACENCY_GRAPHS = append(ADJACENCY_GRAPHS, keypadGraph)
|
|
||||||
ADJACENCY_GRAPHS = append(ADJACENCY_GRAPHS, adjacency.GetAdjancencyGraphFromFile(macKeypadfilePath, "macKepad"))
|
|
||||||
|
|
||||||
l33tFilePath, _ := filepath.Abs("adjacency/L33t.json")
|
|
||||||
L33T_TABLE = adjacency.GetAdjancencyGraphFromFile(l33tFilePath, "l33t")
|
|
||||||
|
|
||||||
MATCHERS = append(MATCHERS, DICTIONARY_MATCHERS...)
|
MATCHERS = append(MATCHERS, DICTIONARY_MATCHERS...)
|
||||||
MATCHERS = append(MATCHERS, spatialMatch)
|
MATCHERS = append(MATCHERS, spatialMatch)
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package scoring
|
package scoring
|
||||||
import (
|
import (
|
||||||
"zxcvbn-go/match"
|
"github.com/nbutton23/zxcvbn-go/match"
|
||||||
"unicode"
|
"unicode"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"sort"
|
"sort"
|
||||||
"regexp"
|
"regexp"
|
||||||
"zxcvbn-go/utils/math"
|
"github.com/nbutton23/zxcvbn-go/utils/math"
|
||||||
"zxcvbn-go/matching"
|
"github.com/nbutton23/zxcvbn-go/matching"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package zxcvbn
|
package zxcvbn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"zxcvbn-go/matching"
|
"github.com/nbutton23/zxcvbn-go/matching"
|
||||||
"zxcvbn-go/scoring"
|
"github.com/nbutton23/zxcvbn-go/scoring"
|
||||||
"time"
|
"time"
|
||||||
"zxcvbn-go/utils/math"
|
"github.com/nbutton23/zxcvbn-go/utils/math"
|
||||||
)
|
)
|
||||||
|
|
||||||
//func main() {
|
//func main() {
|
||||||
|
|
Loading…
Reference in New Issue