File: frequency.go

package info (click to toggle)
golang-github-nbutton23-zxcvbn-go 0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,448 kB
  • sloc: makefile: 6
file content (47 lines) | stat: -rw-r--r-- 1,261 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package frequency

import (
	"encoding/json"
	"github.com/nbutton23/zxcvbn-go/data"
	"log"
)

type FrequencyList struct {
	Name string
	List []string
}

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)
	}
	tempList.Name = name
	return tempList
}