fat
This commit is contained in:
parent
e3fb346bcb
commit
7fa8f55be0
|
@ -1,20 +1,20 @@
|
||||||
package adjacency
|
package adjacency
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"log"
|
||||||
// "fmt"
|
// "fmt"
|
||||||
"github.com/nbutton23/zxcvbn-go/data"
|
"github.com/nbutton23/zxcvbn-go/data"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type AdjacencyGraph struct {
|
type AdjacencyGraph struct {
|
||||||
Graph map[string][]string
|
Graph map[string][]string
|
||||||
averageDegree float64
|
averageDegree float64
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var AdjacencyGph = make(map[string]AdjacencyGraph)
|
||||||
|
|
||||||
var AdjacencyGph = make(map[string]AdjacencyGraph);
|
|
||||||
func init() {
|
func init() {
|
||||||
log.SetFlags(log.Lshortfile)
|
log.SetFlags(log.Lshortfile)
|
||||||
AdjacencyGph["qwerty"] = BuildQwerty()
|
AdjacencyGph["qwerty"] = BuildQwerty()
|
||||||
|
@ -54,7 +54,7 @@ func BuildMacKeypad() AdjacencyGraph {
|
||||||
|
|
||||||
func GetAdjancencyGraphFromFile(data []byte, name string) AdjacencyGraph {
|
func GetAdjancencyGraphFromFile(data []byte, name string) AdjacencyGraph {
|
||||||
|
|
||||||
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)
|
||||||
|
@ -66,7 +66,7 @@ func GetAdjancencyGraphFromFile(data []byte, name string) AdjacencyGraph {
|
||||||
//on qwerty, 'g' has degree 6, being adjacent to 'ftyhbv'. '\' has degree 1.
|
//on qwerty, 'g' has degree 6, being adjacent to 'ftyhbv'. '\' has degree 1.
|
||||||
//this calculates the average over all keys.
|
//this calculates the average over all keys.
|
||||||
//TODO double check that i ported this correctly scoring.coffee ln 5
|
//TODO double check that i ported this correctly scoring.coffee ln 5
|
||||||
func (adjGrp AdjacencyGraph) CalculateAvgDegree() (float64) {
|
func (adjGrp AdjacencyGraph) CalculateAvgDegree() float64 {
|
||||||
if adjGrp.averageDegree != float64(0) {
|
if adjGrp.averageDegree != float64(0) {
|
||||||
return adjGrp.averageDegree
|
return adjGrp.averageDegree
|
||||||
}
|
}
|
||||||
|
@ -87,4 +87,3 @@ func (adjGrp AdjacencyGraph) CalculateAvgDegree() (float64) {
|
||||||
|
|
||||||
return adjGrp.averageDegree
|
return adjGrp.averageDegree
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,11 @@ import (
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func bindataRead(data []byte, name string) ([]byte, error) {
|
func bindataRead(data []byte, name string) ([]byte, error) {
|
||||||
|
@ -296,7 +296,7 @@ func Asset(name string) ([]byte, error) {
|
||||||
// It simplifies safe initialization of global variables.
|
// It simplifies safe initialization of global variables.
|
||||||
func MustAsset(name string) []byte {
|
func MustAsset(name string) []byte {
|
||||||
a, err := Asset(name)
|
a, err := Asset(name)
|
||||||
if (err != nil) {
|
if err != nil {
|
||||||
panic("asset: Asset(" + name + "): " + err.Error())
|
panic("asset: Asset(" + name + "): " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,28 +380,19 @@ type bintree struct {
|
||||||
Func func() (*asset, error)
|
Func func() (*asset, error)
|
||||||
Children map[string]*bintree
|
Children map[string]*bintree
|
||||||
}
|
}
|
||||||
|
|
||||||
var _bintree = &bintree{nil, map[string]*bintree{
|
var _bintree = &bintree{nil, map[string]*bintree{
|
||||||
"data": &bintree{nil, map[string]*bintree{
|
"data": &bintree{nil, map[string]*bintree{
|
||||||
"Dvorak.json": &bintree{dataDvorakJson, map[string]*bintree{
|
"Dvorak.json": &bintree{dataDvorakJson, map[string]*bintree{}},
|
||||||
}},
|
"English.json": &bintree{dataEnglishJson, map[string]*bintree{}},
|
||||||
"English.json": &bintree{dataEnglishJson, map[string]*bintree{
|
"FemaleNames.json": &bintree{dataFemalenamesJson, map[string]*bintree{}},
|
||||||
}},
|
"Keypad.json": &bintree{dataKeypadJson, map[string]*bintree{}},
|
||||||
"FemaleNames.json": &bintree{dataFemalenamesJson, map[string]*bintree{
|
"L33t.json": &bintree{dataL33tJson, map[string]*bintree{}},
|
||||||
}},
|
"MacKeypad.json": &bintree{dataMackeypadJson, map[string]*bintree{}},
|
||||||
"Keypad.json": &bintree{dataKeypadJson, map[string]*bintree{
|
"MaleNames.json": &bintree{dataMalenamesJson, map[string]*bintree{}},
|
||||||
}},
|
"Passwords.json": &bintree{dataPasswordsJson, map[string]*bintree{}},
|
||||||
"L33t.json": &bintree{dataL33tJson, map[string]*bintree{
|
"Qwerty.json": &bintree{dataQwertyJson, map[string]*bintree{}},
|
||||||
}},
|
"Surnames.json": &bintree{dataSurnamesJson, map[string]*bintree{}},
|
||||||
"MacKeypad.json": &bintree{dataMackeypadJson, map[string]*bintree{
|
|
||||||
}},
|
|
||||||
"MaleNames.json": &bintree{dataMalenamesJson, map[string]*bintree{
|
|
||||||
}},
|
|
||||||
"Passwords.json": &bintree{dataPasswordsJson, map[string]*bintree{
|
|
||||||
}},
|
|
||||||
"Qwerty.json": &bintree{dataQwertyJson, map[string]*bintree{
|
|
||||||
}},
|
|
||||||
"Surnames.json": &bintree{dataSurnamesJson, map[string]*bintree{
|
|
||||||
}},
|
|
||||||
}},
|
}},
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
@ -451,4 +442,3 @@ func _filePath(dir, name string) string {
|
||||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
|
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
package frequency
|
package frequency
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/nbutton23/zxcvbn-go/data"
|
"github.com/nbutton23/zxcvbn-go/data"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FrequencyList struct {
|
type FrequencyList struct {
|
||||||
|
@ -11,6 +12,7 @@ type FrequencyList struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var FrequencyLists = make(map[string]FrequencyList)
|
var FrequencyLists = make(map[string]FrequencyList)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
maleFilePath := getAsset("data/MaleNames.json")
|
maleFilePath := getAsset("data/MaleNames.json")
|
||||||
femaleFilePath := getAsset("data/FemaleNames.json")
|
femaleFilePath := getAsset("data/FemaleNames.json")
|
||||||
|
@ -35,7 +37,7 @@ func getAsset(name string) []byte {
|
||||||
}
|
}
|
||||||
func GetStringListFromAsset(data []byte, name string) FrequencyList {
|
func GetStringListFromAsset(data []byte, name string) FrequencyList {
|
||||||
|
|
||||||
var tempList FrequencyList;
|
var tempList FrequencyList
|
||||||
err := json.Unmarshal(data, &tempList)
|
err := json.Unmarshal(data, &tempList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package match
|
package match
|
||||||
|
|
||||||
type Matches []Match
|
type Matches []Match
|
||||||
|
|
||||||
func (s Matches) Len() int {
|
func (s Matches) Len() int {
|
||||||
return len(s)
|
return len(s)
|
||||||
}
|
}
|
||||||
|
@ -16,6 +17,7 @@ func (s Matches) Less(i, j int) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Match struct {
|
type Match struct {
|
||||||
Pattern string
|
Pattern string
|
||||||
I, J int
|
I, J int
|
||||||
|
@ -37,5 +39,4 @@ type DateMatch struct {
|
||||||
Token string
|
Token string
|
||||||
Separator string
|
Separator string
|
||||||
Day, Month, Year int64
|
Day, Month, Year int64
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,19 +1,20 @@
|
||||||
package matching
|
package matching
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"regexp"
|
|
||||||
"strconv"
|
|
||||||
"github.com/nbutton23/zxcvbn-go/frequency"
|
|
||||||
"github.com/nbutton23/zxcvbn-go/adjacency"
|
"github.com/nbutton23/zxcvbn-go/adjacency"
|
||||||
|
"github.com/nbutton23/zxcvbn-go/frequency"
|
||||||
"github.com/nbutton23/zxcvbn-go/match"
|
"github.com/nbutton23/zxcvbn-go/match"
|
||||||
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
// "github.com/deckarep/golang-set"
|
// "github.com/deckarep/golang-set"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
DICTIONARY_MATCHERS []func(password string) []match.Match
|
DICTIONARY_MATCHERS []func(password string) []match.Match
|
||||||
MATCHERS []func(password string) []match.Match
|
MATCHERS []func(password string) []match.Match
|
||||||
ADJACENCY_GRAPHS []adjacency.AdjacencyGraph;
|
ADJACENCY_GRAPHS []adjacency.AdjacencyGraph
|
||||||
KEYBOARD_STARTING_POSITIONS int
|
KEYBOARD_STARTING_POSITIONS int
|
||||||
KEYBOARD_AVG_DEGREE float64
|
KEYBOARD_AVG_DEGREE float64
|
||||||
KEYPAD_STARTING_POSITIONS int
|
KEYPAD_STARTING_POSITIONS int
|
||||||
|
@ -29,7 +30,6 @@ const (
|
||||||
DATE_WITHOUT_SEP_MATCH string = `\d{4,8}`
|
DATE_WITHOUT_SEP_MATCH string = `\d{4,8}`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
loadFrequencyList()
|
loadFrequencyList()
|
||||||
}
|
}
|
||||||
|
@ -83,10 +83,8 @@ func loadFrequencyList() {
|
||||||
MATCHERS = append(MATCHERS, repeatMatch)
|
MATCHERS = append(MATCHERS, repeatMatch)
|
||||||
MATCHERS = append(MATCHERS, SequenceMatch)
|
MATCHERS = append(MATCHERS, SequenceMatch)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func buildDictMatcher(dictName string, rankedDict map[string]int) func(password string) []match.Match {
|
func buildDictMatcher(dictName string, rankedDict map[string]int) func(password string) []match.Match {
|
||||||
return func(password string) []match.Match {
|
return func(password string) []match.Match {
|
||||||
matches := dictionaryMatch(password, dictName, rankedDict)
|
matches := dictionaryMatch(password, dictName, rankedDict)
|
||||||
|
@ -164,7 +162,6 @@ func DateSepMatch(password string) []match.DateMatch {
|
||||||
matches = append(matches, match)
|
matches = append(matches, match)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
matcher = regexp.MustCompile(DATE_RX_YEAR_PREFIX)
|
matcher = regexp.MustCompile(DATE_RX_YEAR_PREFIX)
|
||||||
for _, v := range matcher.FindAllString(password, len(password)) {
|
for _, v := range matcher.FindAllString(password, len(password)) {
|
||||||
splitV := matcher.FindAllStringSubmatch(v, len(v))
|
splitV := matcher.FindAllStringSubmatch(v, len(v))
|
||||||
|
@ -190,11 +187,13 @@ func DateSepMatch(password string) []match.DateMatch {
|
||||||
return out
|
return out
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type DateMatchCandidate struct {
|
type DateMatchCandidate struct {
|
||||||
DayMonth string
|
DayMonth string
|
||||||
Year string
|
Year string
|
||||||
I, J int
|
I, J int
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO I think Im doing this wrong.
|
//TODO I think Im doing this wrong.
|
||||||
func dateWithoutSepMatch(password string) (matches []match.DateMatch) {
|
func dateWithoutSepMatch(password string) (matches []match.DateMatch) {
|
||||||
matcher := regexp.MustCompile(DATE_WITHOUT_SEP_MATCH)
|
matcher := regexp.MustCompile(DATE_WITHOUT_SEP_MATCH)
|
||||||
|
@ -245,7 +244,6 @@ func buildDateMatchCandidateTwo(day, month byte, year string, i, j int) match.Da
|
||||||
return match.DateMatch{Day: intDay, Month: intMonth, Year: intYear, I: i, J: j}
|
return match.DateMatch{Day: intDay, Month: intMonth, Year: intYear, I: i, J: j}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func spatialMatch(password string) (matches []match.Match) {
|
func spatialMatch(password string) (matches []match.Match) {
|
||||||
for _, graph := range ADJACENCY_GRAPHS {
|
for _, graph := range ADJACENCY_GRAPHS {
|
||||||
matches = append(matches, spatialMatchHelper(password, graph)...)
|
matches = append(matches, spatialMatchHelper(password, graph)...)
|
||||||
|
@ -260,7 +258,7 @@ func spatialMatchHelper(password string, graph adjacency.AdjacencyGraph) (matche
|
||||||
turns := 0
|
turns := 0
|
||||||
shiftedCount := 0
|
shiftedCount := 0
|
||||||
|
|
||||||
for ;; {
|
for {
|
||||||
prevChar := password[j-1]
|
prevChar := password[j-1]
|
||||||
found := false
|
found := false
|
||||||
foundDirection := -1
|
foundDirection := -1
|
||||||
|
@ -419,7 +417,7 @@ func SequenceMatch(password string) []match.Match {
|
||||||
}
|
}
|
||||||
|
|
||||||
if seq != "" {
|
if seq != "" {
|
||||||
for ;; {
|
for {
|
||||||
var prevN, curN int
|
var prevN, curN int
|
||||||
if j < len(password) {
|
if j < len(password) {
|
||||||
prevChar, curChar := password[j-1], password[j]
|
prevChar, curChar := password[j-1], password[j]
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
package scoring
|
package scoring
|
||||||
import (
|
|
||||||
"github.com/nbutton23/zxcvbn-go/match"
|
|
||||||
"unicode"
|
|
||||||
"fmt"
|
|
||||||
"math"
|
|
||||||
"sort"
|
|
||||||
"regexp"
|
|
||||||
"github.com/nbutton23/zxcvbn-go/utils/math"
|
|
||||||
"github.com/nbutton23/zxcvbn-go/matching"
|
|
||||||
"github.com/nbutton23/zxcvbn-go/adjacency"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/nbutton23/zxcvbn-go/adjacency"
|
||||||
|
"github.com/nbutton23/zxcvbn-go/match"
|
||||||
|
"github.com/nbutton23/zxcvbn-go/matching"
|
||||||
|
"github.com/nbutton23/zxcvbn-go/utils/math"
|
||||||
|
"math"
|
||||||
|
"regexp"
|
||||||
|
"sort"
|
||||||
|
"unicode"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
START_UPPER string = `^[A-Z][^A-Z]+$`
|
START_UPPER string = `^[A-Z][^A-Z]+$`
|
||||||
|
@ -24,9 +24,8 @@ const (
|
||||||
SINGLE_GUESS float64 = 0.010
|
SINGLE_GUESS float64 = 0.010
|
||||||
NUM_ATTACKERS float64 = 100 //Cores used to make guesses
|
NUM_ATTACKERS float64 = 100 //Cores used to make guesses
|
||||||
SECONDS_PER_GUESS float64 = SINGLE_GUESS / NUM_ATTACKERS
|
SECONDS_PER_GUESS float64 = SINGLE_GUESS / NUM_ATTACKERS
|
||||||
|
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type MinEntropyMatch struct {
|
type MinEntropyMatch struct {
|
||||||
Password string
|
Password string
|
||||||
Entropy float64
|
Entropy float64
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
package zxcvbn_math
|
package zxcvbn_math
|
||||||
|
|
||||||
import "math"
|
import "math"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
I am surprised that I have to define these. . . Maybe i just didn't look hard enough for a lib.
|
I am surprised that I have to define these. . . Maybe i just didn't look hard enough for a lib.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -3,8 +3,8 @@ package zxcvbn
|
||||||
import (
|
import (
|
||||||
"github.com/nbutton23/zxcvbn-go/matching"
|
"github.com/nbutton23/zxcvbn-go/matching"
|
||||||
"github.com/nbutton23/zxcvbn-go/scoring"
|
"github.com/nbutton23/zxcvbn-go/scoring"
|
||||||
"time"
|
|
||||||
"github.com/nbutton23/zxcvbn-go/utils/math"
|
"github.com/nbutton23/zxcvbn-go/utils/math"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
//func main() {
|
//func main() {
|
||||||
|
|
Loading…
Reference in New Issue