diff --git a/.repo-runner.yaml b/.repo-runner.yaml index 2def28a..cd83c6a 100644 --- a/.repo-runner.yaml +++ b/.repo-runner.yaml @@ -9,6 +9,5 @@ commands: environment: CGO_ENABLED: 0 GHUSER: Luzifer - GO111MODULE: on PACKAGES: github.com/Luzifer/password/cmd/password REPO: password diff --git a/.travis.yml b/.travis.yml index 97aae24..6463e3c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,8 @@ language: go go: - - 1.10.x - - 1.11.x - 1.12.x + - 1.13.x - tip install: go get -v github.com/Luzifer/password/lib diff --git a/lib/xkcd.go b/lib/xkcd.go index ec6178d..9c534ab 100644 --- a/lib/xkcd.go +++ b/lib/xkcd.go @@ -9,7 +9,10 @@ import ( "github.com/Luzifer/go_helpers/v2/str" ) -type XKCD struct{} +type XKCD struct { + // Separator to be used between words + Separator string +} var ( // ErrTooFewWords represents an error thrown if the password will @@ -48,9 +51,8 @@ func (x XKCD) GeneratePassword(length int, addDate bool) (string, error) { continue } - password = password + word usedWords = append(usedWords, word) } - return password, nil + return password + strings.Join(usedWords, x.Separator), nil } diff --git a/lib/xkcd_test.go b/lib/xkcd_test.go index 57c2110..bfe4527 100644 --- a/lib/xkcd_test.go +++ b/lib/xkcd_test.go @@ -37,6 +37,20 @@ func TestXKCDDatePrepend(t *testing.T) { } } +func TestXKCDSeparator(t *testing.T) { + gen := NewXKCDGenerator() + gen.Separator = "-" + + pwd, err := gen.GeneratePassword(4, false) + if err != nil { + t.Fatalf("Generated had an error: %s", err) + } + + if !regexp.MustCompile(`^(?:[A-Z][a-z]+-){3}(?:[A-Z][a-z]+)$`).MatchString(pwd) { + t.Errorf("Password %q did not match expected RegEx", pwd) + } +} + func BenchmarkGeneratePasswords4Words(b *testing.B) { for i := 0; i < b.N; i++ { DefaultXKCD.GeneratePassword(4, false)