diff --git a/docs/config.md b/docs/config.md index 7d997f714b..d4663596e7 100644 --- a/docs/config.md +++ b/docs/config.md @@ -110,6 +110,7 @@ This is a list of available options: | `edit.pre-hook` | `string` | This hook is run right before editing a record with `gopass edit` | | `generate.generator` | `string` | Default password generator. `xkcd`, `memorable`, `external` or `` | `` | | `generate.length` | `int` | Default lenght for generated password. | `24` | +| `generate.strict` | `bool` | Use strict mode for generated password. | `false` | | `generate.symbols` | `bool` | Include symbols in generated password. | `false` | | `mounts.path` | `string` | Path to the root store. | `$XDG_DATA_HOME/gopass/stores/root` | | `recipients.check` | `bool` | Check recipients hash. | `false` | diff --git a/internal/action/generate.go b/internal/action/generate.go index 649e7b2d8f..714f8147f7 100644 --- a/internal/action/generate.go +++ b/internal/action/generate.go @@ -239,7 +239,7 @@ func (s *Action) generatePassword(ctx context.Context, c *cli.Context, length, n switch generator { case "memorable": - if c.Bool("strict") { + if isStrict(ctx, c) { return pwgen.GenerateMemorablePassword(pwlen, symbols, true), nil } @@ -247,7 +247,7 @@ func (s *Action) generatePassword(ctx context.Context, c *cli.Context, length, n case "external": return pwgen.GenerateExternal(pwlen) default: - if c.Bool("strict") { + if isStrict(ctx, c) { return pwgen.GeneratePasswordWithAllClasses(pwlen, symbols) } @@ -532,3 +532,17 @@ func filterPrefix(in []string, prefix string) []string { return out } + +func isStrict(ctx context.Context, c *cli.Context) bool { + cfg := config.FromContext(ctx) + + if c.Bool("strict") { + return true + } + + if cfg.IsSet("generate.strict") { + return cfg.GetBool("generate.strict") + } + + return false +}