Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Add config generate.strict (gopasspw#2655)
Browse files Browse the repository at this point in the history
Signed-off-by: Leo Lou <[email protected]>
  • Loading branch information
l4u authored Sep 9, 2023
1 parent fb7f53b commit 63534c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
18 changes: 16 additions & 2 deletions internal/action/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,15 @@ 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
}

return pwgen.GenerateMemorablePassword(pwlen, symbols, false), nil
case "external":
return pwgen.GenerateExternal(pwlen)
default:
if c.Bool("strict") {
if isStrict(ctx, c) {
return pwgen.GeneratePasswordWithAllClasses(pwlen, symbols)
}

Expand Down Expand Up @@ -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
}

0 comments on commit 63534c5

Please sign in to comment.