commit
a22cb81b2e
|
@ -13,9 +13,9 @@ const (
|
|||
START_UPPER string = `^[A-Z][^A-Z]+$`
|
||||
END_UPPER string = `^[^A-Z]+[A-Z]$'`
|
||||
ALL_UPPER string = `^[A-Z]+$`
|
||||
NUM_YEARS = float64(119) // years match against 1900 - 2019
|
||||
NUM_MONTHS = float64(12)
|
||||
NUM_DAYS = float64(31)
|
||||
NUM_YEARS = float64(119) // years match against 1900 - 2019
|
||||
NUM_MONTHS = float64(12)
|
||||
NUM_DAYS = float64(31)
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package entropy
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/nbutton23/zxcvbn-go/match"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
||||
func TestDictionaryEntropyCalculation(t *testing.T) {
|
||||
match := match.Match{
|
||||
Pattern: "dictionary",
|
||||
|
@ -22,31 +21,31 @@ func TestDictionaryEntropyCalculation(t *testing.T) {
|
|||
|
||||
func TestSpatialEntropyCalculation(t *testing.T) {
|
||||
matchPlain := match.Match{
|
||||
Pattern: "spatial",
|
||||
I: 0,
|
||||
J: 5,
|
||||
Token: "asdfgh",
|
||||
DictionaryName:"qwerty",
|
||||
Pattern: "spatial",
|
||||
I: 0,
|
||||
J: 5,
|
||||
Token: "asdfgh",
|
||||
DictionaryName: "qwerty",
|
||||
}
|
||||
entropy := SpatialEntropy(matchPlain, 0, 0)
|
||||
assert.Equal(t, 9.754887502163468, entropy)
|
||||
|
||||
matchShift := match.Match{
|
||||
Pattern: "spatial",
|
||||
I: 0,
|
||||
J: 5,
|
||||
Token: "asdFgh",
|
||||
DictionaryName:"qwerty",
|
||||
Pattern: "spatial",
|
||||
I: 0,
|
||||
J: 5,
|
||||
Token: "asdFgh",
|
||||
DictionaryName: "qwerty",
|
||||
}
|
||||
entropyShift := SpatialEntropy(matchShift, 0, 1)
|
||||
assert.Equal(t, 12.562242424221072, entropyShift)
|
||||
|
||||
matchTurn := match.Match{
|
||||
Pattern: "spatial",
|
||||
I: 0,
|
||||
J: 5,
|
||||
Token: "asdcxz",
|
||||
DictionaryName:"qwerty",
|
||||
Pattern: "spatial",
|
||||
I: 0,
|
||||
J: 5,
|
||||
Token: "asdcxz",
|
||||
DictionaryName: "qwerty",
|
||||
}
|
||||
entropyTurn := SpatialEntropy(matchTurn, 2, 0)
|
||||
assert.Equal(t, 14.080500893768884, entropyTurn)
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
package matching
|
||||
|
||||
import (
|
||||
"github.com/nbutton23/zxcvbn-go/entropy"
|
||||
"github.com/nbutton23/zxcvbn-go/match"
|
||||
"strings"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"github.com/nbutton23/zxcvbn-go/entropy"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
||||
|
||||
func checkDate(day, month, year int64) (bool, int64, int64, int64) {
|
||||
if (12 <= month && month <= 31) && day <= 12 {
|
||||
day, month = month, day
|
||||
|
@ -31,11 +29,11 @@ func dateSepMatcher(password string) []match.Match {
|
|||
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,
|
||||
I: dateMatch.I,
|
||||
J: dateMatch.J,
|
||||
Entropy: entropy.DateEntropy(dateMatch),
|
||||
DictionaryName: "date_match",
|
||||
Token: dateMatch.Token,
|
||||
}
|
||||
|
||||
matches = append(matches, match)
|
||||
|
@ -55,7 +53,7 @@ func dateSepMatchHelper(password string) []match.DateMatch {
|
|||
day, _ := strconv.ParseInt(splitV[0][4], 10, 16)
|
||||
month, _ := strconv.ParseInt(splitV[0][2], 10, 16)
|
||||
year, _ := strconv.ParseInt(splitV[0][6], 10, 16)
|
||||
match := match.DateMatch{Day: day, Month: month, Year: year, Separator: splitV[0][5], I: i, J: j, Token:password[i:j]}
|
||||
match := match.DateMatch{Day: day, Month: month, Year: year, Separator: splitV[0][5], I: i, J: j, Token: password[i:j]}
|
||||
matches = append(matches, match)
|
||||
}
|
||||
|
||||
|
@ -67,7 +65,7 @@ func dateSepMatchHelper(password string) []match.DateMatch {
|
|||
day, _ := strconv.ParseInt(splitV[0][4], 10, 16)
|
||||
month, _ := strconv.ParseInt(splitV[0][6], 10, 16)
|
||||
year, _ := strconv.ParseInt(splitV[0][2], 10, 16)
|
||||
match := match.DateMatch{Day: day, Month: month, Year: year, Separator: splitV[0][5], I: i, J: j, Token:password[i:j]}
|
||||
match := match.DateMatch{Day: day, Month: month, Year: year, Separator: splitV[0][5], I: i, J: j, Token: password[i:j]}
|
||||
matches = append(matches, match)
|
||||
}
|
||||
|
||||
|
@ -92,22 +90,23 @@ type DateMatchCandidate struct {
|
|||
}
|
||||
|
||||
type DateMatchCandidateTwo struct {
|
||||
Day string
|
||||
Day string
|
||||
Month string
|
||||
Year string
|
||||
I, J int
|
||||
Year string
|
||||
I, J int
|
||||
}
|
||||
func dateWithoutSepMatch(password string) ([]match.Match) {
|
||||
|
||||
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,
|
||||
I: dateMatch.I,
|
||||
J: dateMatch.J,
|
||||
Entropy: entropy.DateEntropy(dateMatch),
|
||||
DictionaryName: "date_match",
|
||||
Token: dateMatch.Token,
|
||||
}
|
||||
|
||||
matches = append(matches, match)
|
||||
|
@ -115,6 +114,7 @@ func dateWithoutSepMatch(password string) ([]match.Match) {
|
|||
|
||||
return matches
|
||||
}
|
||||
|
||||
//TODO Has issues with 6 digit dates
|
||||
func dateWithoutSepMatchHelper(password string) (matches []match.DateMatch) {
|
||||
matcher := regexp.MustCompile(DATE_WITHOUT_SEP_MATCH)
|
||||
|
@ -140,16 +140,15 @@ func dateWithoutSepMatchHelper(password string) (matches []match.DateMatch) {
|
|||
candidatesRoundOne = append(candidatesRoundOne, buildDateMatchCandidate(v[0:lastIndex-3], v[lastIndex-3:], i, j))
|
||||
}
|
||||
|
||||
|
||||
var candidatesRoundTwo []DateMatchCandidateTwo
|
||||
for _, c := range candidatesRoundOne {
|
||||
if len(c.DayMonth) == 2 {
|
||||
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))
|
||||
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))
|
||||
candidatesRoundTwo = append(candidatesRoundTwo, buildDateMatchCandidateTwo(c.DayMonth[0:2], c.DayMonth[2:4], c.Year, c.I, c.J))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -159,21 +158,19 @@ func dateWithoutSepMatchHelper(password string) (matches []match.DateMatch) {
|
|||
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 })
|
||||
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})
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package matching
|
||||
|
||||
import (
|
||||
"github.com/nbutton23/zxcvbn-go/match"
|
||||
"github.com/nbutton23/zxcvbn-go/entropy"
|
||||
"github.com/nbutton23/zxcvbn-go/match"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package matching
|
||||
|
||||
import (
|
||||
"github.com/nbutton23/zxcvbn-go/match"
|
||||
"github.com/nbutton23/zxcvbn-go/entropy"
|
||||
"github.com/nbutton23/zxcvbn-go/match"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
||||
func l33tMatch(password string) []match.Match {
|
||||
|
||||
substitutions := relevantL33tSubtable(password)
|
||||
|
@ -16,7 +16,7 @@ func l33tMatch(password string) []match.Match {
|
|||
|
||||
for _, permutation := range permutations {
|
||||
for _, mather := range DICTIONARY_MATCHERS {
|
||||
matches = append(matches,mather(permutation)...)
|
||||
matches = append(matches, mather(permutation)...)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,13 +37,13 @@ func getAllPermutationsOfLeetSubstitutions(password string, substitutionsMap map
|
|||
for _, sub := range splice {
|
||||
if string(char) == sub {
|
||||
var permutation string
|
||||
permutation = password[:index]+value+password[index+1:]
|
||||
permutation = password[:index] + value + password[index+1:]
|
||||
|
||||
permutations = append(permutations, permutation)
|
||||
if index < len(permutation) {
|
||||
tempPermutations := getAllPermutationsOfLeetSubstitutions(permutation[index + 1:], substitutionsMap)
|
||||
tempPermutations := getAllPermutationsOfLeetSubstitutions(permutation[index+1:], substitutionsMap)
|
||||
for _, temp := range tempPermutations {
|
||||
permutations = append(permutations, permutation[:index + 1] + temp)
|
||||
permutations = append(permutations, permutation[:index+1]+temp)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -65,4 +65,4 @@ func relevantL33tSubtable(password string) map[string][]string {
|
|||
}
|
||||
}
|
||||
return relevantSubs
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,10 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
DICTIONARY_MATCHERS []func(password string) []match.Match
|
||||
MATCHERS []func(password string) []match.Match
|
||||
ADJACENCY_GRAPHS []adjacency.AdjacencyGraph
|
||||
L33T_TABLE adjacency.AdjacencyGraph
|
||||
DICTIONARY_MATCHERS []func(password string) []match.Match
|
||||
MATCHERS []func(password string) []match.Match
|
||||
ADJACENCY_GRAPHS []adjacency.AdjacencyGraph
|
||||
L33T_TABLE adjacency.AdjacencyGraph
|
||||
|
||||
SEQUENCES map[string]string
|
||||
)
|
||||
|
@ -74,6 +74,4 @@ func loadFrequencyList() {
|
|||
MATCHERS = append(MATCHERS, dateSepMatcher)
|
||||
MATCHERS = append(MATCHERS, dateWithoutSepMatch)
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package matching
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/nbutton23/zxcvbn-go/match"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"log"
|
||||
"strings"
|
||||
"testing"
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"log"
|
||||
)
|
||||
|
||||
//DateSepMatch("1991-09-11jibjab11.9.1991")
|
||||
|
@ -123,18 +123,16 @@ 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
|
||||
func TestLeetSubTable(t *testing.T){
|
||||
func TestLeetSubTable(t *testing.T) {
|
||||
subs := relevantL33tSubtable("password")
|
||||
assert.Len(t, subs, 0, "password should produce no leet subs")
|
||||
|
||||
|
@ -146,42 +144,39 @@ func TestLeetSubTable(t *testing.T){
|
|||
assert.Equal(t, subs["i"][0], "1")
|
||||
assert.Equal(t, subs["l"][0], "1")
|
||||
|
||||
|
||||
subs = relevantL33tSubtable("4pple@pple")
|
||||
assert.Len(t, subs, 1, "4pple@pple should produce 1 subs")
|
||||
assert.Len(t, subs["a"], 2)
|
||||
|
||||
|
||||
}
|
||||
|
||||
func TestPermutationsOfLeetSubstitutions(t *testing.T){
|
||||
password := "p4ssw0rd" //[passw0rd, password, p4ssword]
|
||||
func TestPermutationsOfLeetSubstitutions(t *testing.T) {
|
||||
password := "p4ssw0rd" //[passw0rd, password, p4ssword]
|
||||
possibleSubs := relevantL33tSubtable(password)
|
||||
|
||||
permutations := getAllPermutationsOfLeetSubstitutions(password, possibleSubs)
|
||||
|
||||
assert.Len(t, permutations, 3, "There should be 3 permutations for "+password)
|
||||
|
||||
password = "p4$sw0rd" //[pa$sw0rd, passw0rd, password, pa$sword, p4ssw0rd, p4ssword, p4$sword]
|
||||
password = "p4$sw0rd" //[pa$sw0rd, passw0rd, password, pa$sword, p4ssw0rd, p4ssword, p4$sword]
|
||||
possibleSubs = relevantL33tSubtable(password)
|
||||
|
||||
permutations = getAllPermutationsOfLeetSubstitutions(password, possibleSubs)
|
||||
assert.Len(t, permutations, 7, "There should be 7 (? check my math) permutations for "+password)
|
||||
|
||||
password = "p4$$w0rd" //[pa$sw0rd, passw0rd, password, pa$sword, p4ssw0rd, p4ssword, p4$sword]
|
||||
password = "p4$$w0rd" //[pa$sw0rd, passw0rd, password, pa$sword, p4ssw0rd, p4ssword, p4$sword]
|
||||
possibleSubs = relevantL33tSubtable(password)
|
||||
|
||||
permutations = getAllPermutationsOfLeetSubstitutions(password, possibleSubs)
|
||||
assert.Len(t, permutations, 15, "Check my math 2*2*2*2 - 1 "+password)
|
||||
|
||||
|
||||
password = "1337"
|
||||
possibleSubs = relevantL33tSubtable(password)
|
||||
permutations = getAllPermutationsOfLeetSubstitutions(password, possibleSubs)
|
||||
assert.Len(t, permutations, 35, "check my math 3*2*2*3 -1 ")
|
||||
}
|
||||
|
||||
func TestLeet(t *testing.T){
|
||||
func TestLeet(t *testing.T) {
|
||||
password := "1337"
|
||||
matches := l33tMatch(password)
|
||||
bytes, _ := json.Marshal(matches)
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package matching
|
||||
|
||||
import (
|
||||
"github.com/nbutton23/zxcvbn-go/match"
|
||||
"github.com/nbutton23/zxcvbn-go/entropy"
|
||||
"github.com/nbutton23/zxcvbn-go/match"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
||||
func repeatMatch(password string) []match.Match {
|
||||
var matches []match.Match
|
||||
|
||||
|
@ -57,4 +56,4 @@ func repeatMatch(password string) []match.Match {
|
|||
matches = append(matches, matchRepeat)
|
||||
}
|
||||
return matches
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package matching
|
||||
|
||||
import (
|
||||
"github.com/nbutton23/zxcvbn-go/match"
|
||||
"github.com/nbutton23/zxcvbn-go/entropy"
|
||||
"github.com/nbutton23/zxcvbn-go/match"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
||||
func sequenceMatch(password string) []match.Match {
|
||||
var matches []match.Match
|
||||
for i := 0; i < len(password); {
|
||||
|
@ -39,12 +38,12 @@ func sequenceMatch(password string) []match.Match {
|
|||
for {
|
||||
var prevN, curN int
|
||||
if j < len(password) {
|
||||
prevChar, curChar := password[j - 1], password[j]
|
||||
prevChar, curChar := password[j-1], password[j]
|
||||
prevN, curN = strings.Index(seq, string(prevChar)), strings.Index(seq, string(curChar))
|
||||
}
|
||||
|
||||
if j == len(password) || curN - prevN != seqDirection {
|
||||
if j - i > 2 {
|
||||
if j == len(password) || curN-prevN != seqDirection {
|
||||
if j-i > 2 {
|
||||
matchSequence := match.Match{
|
||||
Pattern: "sequence",
|
||||
I: i,
|
||||
|
@ -66,4 +65,4 @@ func sequenceMatch(password string) []match.Match {
|
|||
i = j
|
||||
}
|
||||
return matches
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package matching
|
||||
|
||||
import (
|
||||
"github.com/nbutton23/zxcvbn-go/match"
|
||||
"github.com/nbutton23/zxcvbn-go/entropy"
|
||||
"strings"
|
||||
"github.com/nbutton23/zxcvbn-go/adjacency"
|
||||
"github.com/nbutton23/zxcvbn-go/entropy"
|
||||
"github.com/nbutton23/zxcvbn-go/match"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func spatialMatch(password string) (matches []match.Match) {
|
||||
|
@ -78,4 +78,3 @@ func spatialMatchHelper(password string, graph adjacency.AdjacencyGraph) (matche
|
|||
}
|
||||
return matches
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
//password :="Testaaatyhg890l33t"
|
||||
//fmt.Println(zxcvbn.PasswordStrength(password, nil))
|
||||
//password :="Testaaatyhg890l33t"
|
||||
//fmt.Println(zxcvbn.PasswordStrength(password, nil))
|
||||
|
||||
length := 5
|
||||
//pass := "68f9698fe2540c525fe35b15c6ae1a1788e079962b2ada3d1872c7665c95e148"
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
|
||||
func PasswordStrength(password string, userInputs []string) scoring.MinEntropyMatch {
|
||||
start := time.Now()
|
||||
matches := matching.Omnimatch(password, userInputs)
|
||||
|
|
|
@ -28,7 +28,7 @@ var numTestRan int
|
|||
|
||||
func TestPasswordStrength(t *testing.T) {
|
||||
|
||||
// Expected calculated by running zxcvbn-python
|
||||
// Expected calculated by running zxcvbn-python
|
||||
runTest(t, "zxcvbn", float64(6.845490050944376))
|
||||
runTest(t, "Tr0ub4dour&3", float64(17.296))
|
||||
runTest(t, "qwER43@!", float64(26.44))
|
||||
|
@ -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)) // I think this is wrong. . .
|
||||
runTest(t, "13/3/1997", float64(2)) // I think this is wrong. . .
|
||||
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))
|
||||
|
|
Loading…
Reference in New Issue