Fixed dateWithOutSepMatch for dates with 8 digits.
This commit is contained in:
parent
09242c1934
commit
957cde7393
|
@ -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}
|
||||
}
|
||||
|
|
|
@ -72,6 +72,8 @@ func loadFrequencyList() {
|
|||
MATCHERS = append(MATCHERS, sequenceMatch)
|
||||
MATCHERS = append(MATCHERS, l33tMatch)
|
||||
MATCHERS = append(MATCHERS, dateSepMatcher)
|
||||
MATCHERS = append(MATCHERS, dateWithoutSepMatch)
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue