Added data binding. Moved all the Json files into on folder

This commit is contained in:
Nathan Button 2015-10-06 18:14:08 -06:00
parent 17f81ad607
commit 80ad1b1d96
16 changed files with 540 additions and 71 deletions

View File

@ -2,9 +2,8 @@ package adjacency
import (
"log"
"encoding/json"
"io/ioutil"
// "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 {
filePath, _ := filepath.Abs("Qwerty.json")
return GetAdjancencyGraphFromFile(filePath, "qwerty")
data, err := zxcvbn_data.Asset("data/Qwerty.json")
if err != nil {
panic("Can't find asset")
}
return GetAdjancencyGraphFromFile(data, "qwerty")
}
func buildDvorak() AdjacencyGraph {
filePath, _ := filepath.Abs("Dvorak.json")
return GetAdjancencyGraphFromFile(filePath, "dvorak")
data, err := zxcvbn_data.Asset("data/Dvorak.json")
if err != nil {
panic("Can't find asset")
}
return GetAdjancencyGraphFromFile(data, "dvorak")
}
func buildKeypad() AdjacencyGraph {
filePath, _ := filepath.Abs("Keypad.json")
return GetAdjancencyGraphFromFile(filePath, "keypad")
data, err := zxcvbn_data.Asset("data/Keypad.json")
if err != nil {
panic("Can't find asset")
}
return GetAdjancencyGraphFromFile(data, "keypad")
}
func buildMacKeypad() AdjacencyGraph {
filePath, _ := filepath.Abs("MacKeypad.json")
return GetAdjancencyGraphFromFile(filePath, "mac_keypad")
data, err := zxcvbn_data.Asset("data/MacKeypad.json")
if err != nil {
panic("Can't find asset")
}
return GetAdjancencyGraphFromFile(data, "mac_keypad")
}
func GetAdjancencyGraphFromFile(filePath string, name string) AdjacencyGraph {
data, err := ioutil.ReadFile(filePath)
if err != nil {
log.Fatal(err)
}
func GetAdjancencyGraphFromFile(data []byte, name string) AdjacencyGraph {
var graph AdjacencyGraph;
err = json.Unmarshal(data, &graph)
err := json.Unmarshal(data, &graph)
if err != nil {
log.Fatal(err)
}

454
data/bindata.go Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,26 +1,45 @@
package frequency
import (
"io/ioutil"
"log"
"encoding/json"
"github.com/nbutton23/zxcvbn-go/data"
)
type listWrapper struct {
type FrequencyList struct {
Name string
List []string
}
func GetStringListFromFile(filePath string) []string {
data, err := ioutil.ReadFile(filePath)
var FrequencyLists = make(map[string]FrequencyList)
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 {
log.Fatal(err)
}
var tempList listWrapper;
err = json.Unmarshal(data, &tempList)
if err != nil {
log.Fatal(err)
}
return tempList.List
tempList.Name = name
return tempList
}

View File

@ -3,10 +3,9 @@ import (
"strings"
"regexp"
"strconv"
"zxcvbn-go/frequency"
"path/filepath"
"zxcvbn-go/adjacency"
"zxcvbn-go/match"
"github.com/nbutton23/zxcvbn-go/frequency"
"github.com/nbutton23/zxcvbn-go/adjacency"
"github.com/nbutton23/zxcvbn-go/match"
"sort"
// "github.com/deckarep/golang-set"
)
@ -53,39 +52,23 @@ func Omnimatch(password string, userInputs []string) (matches []match.Match) {
}
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))))
DICTIONARY_MATCHERS = append(DICTIONARY_MATCHERS, buildDictMatcher("FemaleNames", buildRankedDict(frequency.GetStringListFromFile(femaleFilePath))))
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))))
for n, list := range frequency.FrequencyLists {
DICTIONARY_MATCHERS = append(DICTIONARY_MATCHERS,buildDictMatcher(n, buildRankedDict(list.List)))
}
qwertyfilePath, _ := filepath.Abs("adjacency/Qwerty.json")
dvorakfilePath, _ := filepath.Abs("adjacency/Dvorak.json")
keypadfilePath, _ := filepath.Abs("adjacency/Keypad.json")
macKeypadfilePath, _ := filepath.Abs("adjacency/MacKeypad.json")
KEYBOARD_AVG_DEGREE = adjacency.AdjacencyGph["querty"].CalculateAvgDegree()
KEYBOARD_STARTING_POSITIONS = len(adjacency.AdjacencyGph["querty"].Graph)
KEYPAD_AVG_DEGREE = adjacency.AdjacencyGph["keypad"].CalculateAvgDegree()
KEYPAD_STARTING_POSITIONS = len(adjacency.AdjacencyGph["keypad"].Graph)
qwertGraph := adjacency.GetAdjancencyGraphFromFile(qwertyfilePath, "qwert")
keypadGraph := adjacency.GetAdjancencyGraphFromFile(keypadfilePath, "keypad")
KEYBOARD_AVG_DEGREE = qwertGraph.CalculateAvgDegree()
KEYBOARD_STARTING_POSITIONS = len(qwertGraph.Graph)
KEYPAD_AVG_DEGREE = keypadGraph.CalculateAvgDegree()
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")
ADJACENCY_GRAPHS = append(ADJACENCY_GRAPHS, adjacency.AdjacencyGph["querty"])
ADJACENCY_GRAPHS = append(ADJACENCY_GRAPHS, adjacency.AdjacencyGph["dvorak"])
ADJACENCY_GRAPHS = append(ADJACENCY_GRAPHS, adjacency.AdjacencyGph["keypad"])
ADJACENCY_GRAPHS = append(ADJACENCY_GRAPHS, adjacency.AdjacencyGph["macKeypad"])
//
// l33tFilePath, _ := filepath.Abs("adjacency/L33t.json")
// L33T_TABLE = adjacency.GetAdjancencyGraphFromFile(l33tFilePath, "l33t")
MATCHERS = append(MATCHERS, DICTIONARY_MATCHERS...)
MATCHERS = append(MATCHERS, spatialMatch)

View File

@ -1,13 +1,13 @@
package scoring
import (
"zxcvbn-go/match"
"github.com/nbutton23/zxcvbn-go/match"
"unicode"
"fmt"
"math"
"sort"
"regexp"
"zxcvbn-go/utils/math"
"zxcvbn-go/matching"
"github.com/nbutton23/zxcvbn-go/utils/math"
"github.com/nbutton23/zxcvbn-go/matching"
)

View File

@ -1,10 +1,10 @@
package zxcvbn
import (
"zxcvbn-go/matching"
"zxcvbn-go/scoring"
"github.com/nbutton23/zxcvbn-go/matching"
"github.com/nbutton23/zxcvbn-go/scoring"
"time"
"zxcvbn-go/utils/math"
"github.com/nbutton23/zxcvbn-go/utils/math"
)
//func main() {