Skip to content

Commit

Permalink
Language switch for xkcd (gopasspw#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinhoefling authored and dominikschulz committed Oct 18, 2017
1 parent 0d8c871 commit 7a8462e
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 9,097 deletions.
5 changes: 4 additions & 1 deletion action/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ func (s *Action) Generate(ctx context.Context, c *cli.Context) error {

var password string
if xkcd {
password = xkcdgen.RandomLengthDelim(pwlen, xkcdSeparator)
password, err = xkcdgen.RandomLengthDelim(pwlen, xkcdSeparator, c.String("xkcdlang"))
if err != nil {
return err
}
} else {
password = pwgen.GeneratePassword(pwlen, symbols)
}
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,11 @@ func main() {
Usage: "Word separator for generated xkcd style password. Implies -xkcd",
Value: "",
},
cli.StringFlag{
Name: "xkcdlang, xl",
Usage: "Language to generate password from, currently de (german) and en (english, default) are supported",
Value: "en",
},
},
},
{
Expand Down
16 changes: 10 additions & 6 deletions utils/pwgen/xkcdgen/pwgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@ import "github.com/martinhoefling/goxkcdpwgen/xkcdpwgen"

// Random returns a random passphrase combined from four words
func Random() string {
return RandomLength(4)
password, _ := RandomLength(4, "en")
return password
}

// RandomLength returns a random passphrase combined from the desired number
// of words
func RandomLength(length int) string {
return RandomLengthDelim(length, " ")
func RandomLength(length int, lang string) (string, error) {
return RandomLengthDelim(length, " ", lang)
}

// RandomLengthDelim returns a random passphrase combined from the desired number
// of words and the given delimiter
func RandomLengthDelim(length int, delim string) string {
// of words and the given delimiter. Words are drawn from lang
func RandomLengthDelim(length int, delim, lang string) (string, error) {
g := xkcdpwgen.NewGenerator()
g.SetNumWords(length)
g.SetDelimiter(delim)
g.SetCapitalize(delim == "")
return string(g.GeneratePassword())
if err := g.UseLangWordlist(lang); err != nil {
return "", err
}
return string(g.GeneratePassword()), nil
}
2 changes: 2 additions & 0 deletions vendor/github.com/martinhoefling/goxkcdpwgen/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions vendor/github.com/martinhoefling/goxkcdpwgen/xkcdpwgen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7a8462e

Please sign in to comment.