2015-09-29 22:35:25 +00:00
|
|
|
package frequency
|
2016-01-13 22:49:04 +00:00
|
|
|
|
2015-09-29 22:35:25 +00:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
2015-10-07 00:14:08 +00:00
|
|
|
"github.com/nbutton23/zxcvbn-go/data"
|
2016-01-13 22:49:04 +00:00
|
|
|
"log"
|
2015-09-29 22:35:25 +00:00
|
|
|
)
|
|
|
|
|
2015-10-07 00:14:08 +00:00
|
|
|
type FrequencyList struct {
|
|
|
|
Name string
|
2015-09-29 22:35:25 +00:00
|
|
|
List []string
|
|
|
|
}
|
|
|
|
|
2015-10-07 00:14:08 +00:00
|
|
|
var FrequencyLists = make(map[string]FrequencyList)
|
2016-01-13 22:49:04 +00:00
|
|
|
|
2015-10-07 00:14:08 +00:00
|
|
|
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")
|
2015-09-29 22:35:25 +00:00
|
|
|
|
2015-10-07 00:14:08 +00:00
|
|
|
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)
|
2015-09-29 22:35:25 +00:00
|
|
|
if err != nil {
|
2015-10-07 00:14:08 +00:00
|
|
|
panic("Error getting asset " + name)
|
2015-09-29 22:35:25 +00:00
|
|
|
}
|
|
|
|
|
2015-10-07 00:14:08 +00:00
|
|
|
return data
|
|
|
|
}
|
|
|
|
func GetStringListFromAsset(data []byte, name string) FrequencyList {
|
2015-09-29 22:35:25 +00:00
|
|
|
|
2016-01-13 22:49:04 +00:00
|
|
|
var tempList FrequencyList
|
2015-10-07 00:14:08 +00:00
|
|
|
err := json.Unmarshal(data, &tempList)
|
2015-09-29 22:35:25 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2015-10-07 00:14:08 +00:00
|
|
|
tempList.Name = name
|
|
|
|
return tempList
|
2016-01-13 22:49:04 +00:00
|
|
|
}
|