diff --git a/frequency/frequency.go b/frequency/frequency.go index 5ef1979..d056e4d 100644 --- a/frequency/frequency.go +++ b/frequency/frequency.go @@ -6,11 +6,13 @@ import ( "github.com/nbutton23/zxcvbn-go/data" ) + // List holds a frequency list type List struct { Name string List []string } + // Lists holds all the frequency list in a map var Lists = make(map[string]List) diff --git a/match/match.go b/match/match.go index 5d3ef30..dd30bea 100644 --- a/match/match.go +++ b/match/match.go @@ -1,6 +1,6 @@ package match -//Matches is an alies for []Match used for sorting +//Matches is an alies for []Match used for sorting type Matches []Match func (s Matches) Len() int { diff --git a/matching/dateMatchers.go b/matching/dateMatchers.go index 012bc06..8dfdf24 100644 --- a/matching/dateMatchers.go +++ b/matching/dateMatchers.go @@ -1,23 +1,23 @@ package matching import ( + "regexp" "strconv" "strings" - "regexp" "github.com/nbutton23/zxcvbn-go/entropy" "github.com/nbutton23/zxcvbn-go/match" ) const ( - dateSepMatcherName = "DATESEP" + dateSepMatcherName = "DATESEP" dateWithOutSepMatcherName = "DATEWITHOUT" ) var ( - dateRxYearSuffix = regexp.MustCompile( `((\d{1,2})(\s|-|\/|\\|_|\.)(\d{1,2})(\s|-|\/|\\|_|\.)(19\d{2}|200\d|201\d|\d{2}))`) - dateRxYearPrefix = regexp.MustCompile(`((19\d{2}|200\d|201\d|\d{2})(\s|-|/|\\|_|\.)(\d{1,2})(\s|-|/|\\|_|\.)(\d{1,2}))`) - dateWithOutSepMatch = regexp.MustCompile( `\d{4,8}`) + dateRxYearSuffix = regexp.MustCompile(`((\d{1,2})(\s|-|\/|\\|_|\.)(\d{1,2})(\s|-|\/|\\|_|\.)(19\d{2}|200\d|201\d|\d{2}))`) + dateRxYearPrefix = regexp.MustCompile(`((19\d{2}|200\d|201\d|\d{2})(\s|-|/|\\|_|\.)(\d{1,2})(\s|-|/|\\|_|\.)(\d{1,2}))`) + dateWithOutSepMatch = regexp.MustCompile(`\d{4,8}`) ) //FilterDateSepMatcher can be pass to zxcvbn-go.PasswordStrength to skip that matcher diff --git a/matching/spatialMatch.go b/matching/spatialMatch.go index 961d9b1..fd858f5 100644 --- a/matching/spatialMatch.go +++ b/matching/spatialMatch.go @@ -58,7 +58,7 @@ func spatialMatchHelper(password string, graph adjacency.Graph) (matches []match if lastDirection != foundDirection { //adding a turn is correct even in the initial case when last_direction is null: //every spatial pattern starts with a turn. - turns++ + turns++ lastDirection = foundDirection } break diff --git a/testapp/main.go b/testapp/main.go index e6d7fe6..38772bb 100644 --- a/testapp/main.go +++ b/testapp/main.go @@ -1,12 +1,19 @@ package main import ( + "bufio" "fmt" + "os" + "github.com/nbutton23/zxcvbn-go" ) func main() { - password := "Testaaatyhg890l33t" + + fmt.Println("Enter password:") + reader := bufio.NewReader(os.Stdin) + password, _ := reader.ReadString('\n') + //password := "Testaaatyhg890l33t" passwordStenght := zxcvbn.PasswordStrength(password, nil) diff --git a/zxcvbn_test.go b/zxcvbn_test.go index 4f38114..0410a70 100644 --- a/zxcvbn_test.go +++ b/zxcvbn_test.go @@ -1,8 +1,8 @@ package zxcvbn import ( - "testing" "math" + "testing" ) /** @@ -53,20 +53,19 @@ func TestPasswordStrength(t *testing.T) { runTest(t, "rWibMFACxAUGZmxhVncy", float64(104.551)) runTest(t, "Ba9ZyWABu99[BK#6MBgbH88Tofv)vs$", float64(161.278)) } - + var formatString = "%s : error should be less than %.2f Acctual error: %.4f Expected entropy %.4f Actual entropy %.4f \n" - func runTest(t *testing.T, password string, pythonEntropy float64) { - + goEntropy := GoPasswordStrength(password, nil) perror := math.Abs(goEntropy-pythonEntropy) / pythonEntropy - if perror > allowableError { - t.Logf(formatString, password, allowableError, perror, pythonEntropy, goEntropy ) + if perror > allowableError { + t.Logf(formatString, password, allowableError, perror, pythonEntropy, goEntropy) // t.Fail() - } + } } func GoPasswordStrength(password string, userInputs []string) float64 {