go format + make testapp take input

This commit is contained in:
Martin Holst Swende 2018-09-12 15:04:35 +02:00
parent be3c235ccd
commit fbd806564e
No known key found for this signature in database
GPG Key ID: 683B438C05A5DDF0
6 changed files with 23 additions and 15 deletions

View File

@ -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)

View File

@ -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 {

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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 {