From 957cde7393fe985783da6ade76b9fc6ff2248919 Mon Sep 17 00:00:00 2001 From: Nathan Button Date: Sun, 29 May 2016 18:11:57 -0600 Subject: [PATCH] Fixed dateWithOutSepMatch for dates with 8 digits. --- matching/dateMatchers.go | 76 ++++++++++++++++++++++++++++++++------- matching/matching.go | 2 ++ matching/matching_test.go | 10 ++++++ testapp/main.go | 36 +++++++++++++++++++ zxcvbn.go | 4 --- zxcvbn_test.go | 4 +-- 6 files changed, 113 insertions(+), 19 deletions(-) create mode 100644 testapp/main.go diff --git a/matching/dateMatchers.go b/matching/dateMatchers.go index 9babd51..e3b39e5 100644 --- a/matching/dateMatchers.go +++ b/matching/dateMatchers.go @@ -19,7 +19,7 @@ func checkDate(day, month, year int64) (bool, int64, int64, int64) { return false, 0, 0, 0 } - if !(1900 <= year && year <= 2019) { + if !((1900 <= year && year <= 2019) || (0 <= year && year <= 99)) { return false, 0, 0, 0 } @@ -91,8 +91,32 @@ type DateMatchCandidate struct { I, J int } -//TODO I think Im doing this wrong. -func dateWithoutSepMatch(password string) (matches []match.DateMatch) { +type DateMatchCandidateTwo struct { + Day string + Month string + Year string + I, J int +} +func dateWithoutSepMatch(password string) ([]match.Match) { + dateMatches := dateWithoutSepMatchHelper(password) + + var matches []match.Match + for _, dateMatch := range dateMatches { + match := match.Match{ + I:dateMatch.I, + J:dateMatch.J, + Entropy:entropy.DateEntropy(dateMatch), + DictionaryName:"date_match", + Token:dateMatch.Token, + } + + matches = append(matches, match) + } + + return matches +} +//TODO Has issues with 6 digit dates +func dateWithoutSepMatchHelper(password string) (matches []match.DateMatch) { matcher := regexp.MustCompile(DATE_WITHOUT_SEP_MATCH) for _, v := range matcher.FindAllString(password, len(password)) { i := strings.Index(password, v) @@ -113,15 +137,46 @@ func dateWithoutSepMatch(password string) (matches []match.DateMatch) { candidatesRoundOne = append(candidatesRoundOne, buildDateMatchCandidate(v[4:], v[0:4], i, j)) //4-digit year sufix - candidatesRoundOne = append(candidatesRoundOne, buildDateMatchCandidate(v[0:lastIndex-4], v[lastIndex-4:], i, j)) + candidatesRoundOne = append(candidatesRoundOne, buildDateMatchCandidate(v[0:lastIndex-3], v[lastIndex-3:], i, j)) } - var candidatesRoundTwo []match.DateMatch + + var candidatesRoundTwo []DateMatchCandidateTwo for _, c := range candidatesRoundOne { if len(c.DayMonth) == 2 { - candidatesRoundTwo = append(candidatesRoundTwo, buildDateMatchCandidateTwo(c.DayMonth[0], c.DayMonth[1], c.Year, c.I, c.J)) + candidatesRoundTwo = append(candidatesRoundTwo, buildDateMatchCandidateTwo(c.DayMonth[0:0], c.DayMonth[1:1], c.Year, c.I, c.J)) + } else if len(c.DayMonth) == 3 { + candidatesRoundTwo = append(candidatesRoundTwo, buildDateMatchCandidateTwo(c.DayMonth[0:2],c.DayMonth[2:2], c.Year, c.I, c.J)) + candidatesRoundTwo = append(candidatesRoundTwo, buildDateMatchCandidateTwo(c.DayMonth[0:0],c.DayMonth[1:3], c.Year, c.I, c.J)) + } else if len(c.DayMonth) == 4 { + candidatesRoundTwo = append(candidatesRoundTwo, buildDateMatchCandidateTwo(c.DayMonth[0:2],c.DayMonth[2:4], c.Year, c.I, c.J)) } } + + for _, candidate := range candidatesRoundTwo { + intDay, err := strconv.ParseInt(candidate.Day, 10, 16) + if err != nil { + continue + } + + + intMonth, err := strconv.ParseInt(candidate.Month, 10, 16) + + if err != nil { + continue + } + + + intYear, err := strconv.ParseInt(candidate.Year, 10, 16) + if err != nil { + continue + } + + if ok, _, _, _:= checkDate(intDay, intMonth, intYear); ok{ + matches = append(matches, match.DateMatch{Token:password, Pattern:"date", Day:intDay, Month:intMonth, Year:intYear, I:i, J:j }) + } + + } } return matches @@ -131,12 +186,7 @@ func buildDateMatchCandidate(dayMonth, year string, i, j int) DateMatchCandidate return DateMatchCandidate{DayMonth: dayMonth, Year: year, I: i, J: j} } -func buildDateMatchCandidateTwo(day, month byte, year string, i, j int) match.DateMatch { - sDay := string(day) - sMonth := string(month) - intDay, _ := strconv.ParseInt(sDay, 10, 16) - intMonth, _ := strconv.ParseInt(sMonth, 10, 16) - intYear, _ := strconv.ParseInt(year, 10, 16) +func buildDateMatchCandidateTwo(day, month string, year string, i, j int) DateMatchCandidateTwo { - return match.DateMatch{Day: intDay, Month: intMonth, Year: intYear, I: i, J: j} + return DateMatchCandidateTwo{Day: day, Month: month, Year: year, I: i, J: j} } diff --git a/matching/matching.go b/matching/matching.go index f6fc98d..d913f35 100644 --- a/matching/matching.go +++ b/matching/matching.go @@ -72,6 +72,8 @@ func loadFrequencyList() { MATCHERS = append(MATCHERS, sequenceMatch) MATCHERS = append(MATCHERS, l33tMatch) MATCHERS = append(MATCHERS, dateSepMatcher) + MATCHERS = append(MATCHERS, dateWithoutSepMatch) + } diff --git a/matching/matching_test.go b/matching/matching_test.go index 1446036..1c5dfab 100644 --- a/matching/matching_test.go +++ b/matching/matching_test.go @@ -7,6 +7,7 @@ import ( "testing" "fmt" "encoding/json" + "log" ) //DateSepMatch("1991-09-11jibjab11.9.1991") @@ -121,6 +122,15 @@ func TestDictionaryMatch(t *testing.T) { func TestDateWithoutSepMatch(t *testing.T) { matches := dateWithoutSepMatch("11091991") assert.Len(t, matches, 1, "Lenght should be 1") + + + matches = dateWithoutSepMatch("20010911") + assert.Len(t, matches, 1, "Lenght should be 1") + log.Println(matches) + + + //matches := dateWithoutSepMatch("110991") + //assert.Len(t, matches, 21, "Lenght should be blarg") } //l33t diff --git a/testapp/main.go b/testapp/main.go new file mode 100644 index 0000000..58b1afc --- /dev/null +++ b/testapp/main.go @@ -0,0 +1,36 @@ +package main + +import ( + "fmt" + "github.com/nbutton23/zxcvbn-go" + "time" +) + +func main() { + //password :="Testaaatyhg890l33t" + //fmt.Println(zxcvbn.PasswordStrength(password, nil)) + + length := 5 + //pass := "68f9698fe2540c525fe35b15c6ae1a1788e079962b2ada3d1872c7665c95e148" + pass := "NathanButtonTheAmazingAndAwesom12340987tyghjuikolpblkjhgfdsalabcdef" + + for length <= len(pass) { + fmt.Printf("\nTested Password: %s\n", pass[0:length]) + startTime := time.Now().UTC() + + quality := zxcvbn.PasswordStrength(pass[0:length], []string{}) + + fmt.Printf( + `Password score (0-4): %d +Estimated entropy (bit): %f +Estimated time to crack: %s%s`, + quality.Score, + quality.Entropy, + quality.CrackTimeDisplay, "\n", + ) + + length += 1 + runtime := time.Now().UTC().Sub(startTime) + fmt.Printf("Evaluation took: %s\n", runtime.String()) + } +} diff --git a/zxcvbn.go b/zxcvbn.go index 02e7d4b..1391b46 100644 --- a/zxcvbn.go +++ b/zxcvbn.go @@ -7,10 +7,6 @@ import ( "time" ) -//func main() { -// password :="Testaaatyhg890l33t" -// fmt.Println(PasswordStrength(password, nil)) -//} func PasswordStrength(password string, userInputs []string) scoring.MinEntropyMatch { start := time.Now() diff --git a/zxcvbn_test.go b/zxcvbn_test.go index b1c0f30..6e04ab5 100644 --- a/zxcvbn_test.go +++ b/zxcvbn_test.go @@ -36,8 +36,8 @@ func TestPasswordStrength(t *testing.T) { runTest(t, "coRrecth0rseba++ery9.23.2007staple$", float64(66.018)) runTest(t, "D0g..................", float64(20.678)) runTest(t, "abcdefghijk987654321", float64(11.951)) - runTest(t, "neverforget", float64(2)) - runTest(t, "13/3/1997", float64(2)) + runTest(t, "neverforget", float64(2)) // I think this is wrong. . . + runTest(t, "13/3/1997", float64(2)) // I think this is wrong. . . runTest(t, "neverforget13/3/1997", float64(32.628)) runTest(t, "1qaz2wsx3edc", float64(19.314)) runTest(t, "temppass22", float64(22.179))