Enforce min and max length for string and password types in the wizard
RELEASE_NOTES=[BUGFIX] Wizard: Enforce min and max length.
Fixes
@@ -222,6 +222,12 @@ func mkActFunc(tpl Template, s *root.Store, cb ActionCallback) func(context.Cont
if err != nil {
return err
}
+ if v.Min > 0 && len(sv) < v.Min {
+ return fmt.Errorf("%s is too short (needs %d)", v.Name, v.Min)
+ }
+ if v.Max > 0 && len(sv) > v.Min {
+ return fmt.Errorf("%s is too long (at most %d)", v.Name, v.Max)
+ }
if wantForName[k] {
nameParts = append(nameParts, sv)
}
@@ -259,6 +265,12 @@ func mkActFunc(tpl Template, s *root.Store, cb ActionCallback) func(context.Cont
if err != nil {
return err
}
+ if v.Min > 0 && len(password) < v.Min {
+ return fmt.Errorf("%s is too short (needs %d)", v.Name, v.Min)
+ }
+ if v.Max > 0 && len(password) > v.Min {
+ return fmt.Errorf("%s is too long (at most %d)", v.Name, v.Max)
+ }
}
sec.SetPassword(password)
