Skip to content

Commit

Permalink
added the ability to disadle the password policy
Browse files Browse the repository at this point in the history
  • Loading branch information
2403905 committed Dec 15, 2023
1 parent 48c0ea5 commit ff56cb3
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 3 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/enhancement-disabled-password-policy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Disable the password policy

We add the environment variable that allow to disable the password policy.

https://github.com/cs3org/reva/pull/4409
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type config struct {
}

type passwordPolicy struct {
Disabled bool `mapstructure:"disabled"`
MinCharacters int `mapstructure:"min_characters"`
MinLowerCaseCharacters int `mapstructure:"min_lowercase_characters"`
MinUpperCaseCharacters int `mapstructure:"min_uppercase_characters"`
Expand Down Expand Up @@ -173,9 +174,10 @@ func New(m map[string]interface{}, ss *grpc.Server) (rgrpc.Service, error) {

func newPasswordPolicy(c *passwordPolicy) password.Validator {
if c == nil {
return password.NewPasswordPolicy(0, 0, 0, 0, 0, nil)
return password.NewPasswordPolicy(true, 0, 0, 0, 0, 0, nil)
}
return password.NewPasswordPolicy(
c.Disabled,
c.MinCharacters,
c.MinLowerCaseCharacters,
c.MinUpperCaseCharacters,
Expand Down
1 change: 1 addition & 0 deletions internal/http/services/owncloud/ocs/data/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ type CapabilitiesGraph struct {

// CapabilitiesPasswordPolicy hold the password policy capabilities
type CapabilitiesPasswordPolicy struct {
Disabled bool `json:"disabled" xml:"disabled" mapstructure:"disabled"`
MinCharacters int `json:"min_characters" xml:"min_characters" mapstructure:"min_characters"`
MaxCharacters int `json:"max_characters" xml:"max_characters" mapstructure:"max_characters"`
MinLowerCaseCharacters int `json:"min_lowercase_characters" xml:"min_lowercase_characters" mapstructure:"min_lowercase_characters"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1734,9 +1734,10 @@ func publicPwdEnforced(c *config.Config) passwordEnforced {

func passwordPolicies(c *config.Config) password.Validator {
if c.Capabilities.Capabilities == nil || c.Capabilities.Capabilities.PasswordPolicy == nil {
return password.NewPasswordPolicy(0, 0, 0, 0, 0, nil)
return password.NewPasswordPolicy(true, 0, 0, 0, 0, 0, nil)
}
return password.NewPasswordPolicy(
c.Capabilities.Capabilities.PasswordPolicy.Disabled,
c.Capabilities.Capabilities.PasswordPolicy.MinCharacters,
c.Capabilities.Capabilities.PasswordPolicy.MinLowerCaseCharacters,
c.Capabilities.Capabilities.PasswordPolicy.MinUpperCaseCharacters,
Expand Down
7 changes: 6 additions & 1 deletion pkg/password/password_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Validator interface {

// Policies represents a password validation rules
type Policies struct {
disabled bool
minCharacters int
minLowerCaseCharacters int
minUpperCaseCharacters int
Expand All @@ -29,8 +30,9 @@ type Policies struct {
}

// NewPasswordPolicy returns a new NewPasswordPolicy instance
func NewPasswordPolicy(minCharacters, minLowerCaseCharacters, minUpperCaseCharacters, minDigits, minSpecialCharacters int, bannedPasswordsList map[string]struct{}) Validator {
func NewPasswordPolicy(disabled bool, minCharacters, minLowerCaseCharacters, minUpperCaseCharacters, minDigits, minSpecialCharacters int, bannedPasswordsList map[string]struct{}) Validator {
p := &Policies{
disabled: disabled,
minCharacters: minCharacters,
minLowerCaseCharacters: minLowerCaseCharacters,
minUpperCaseCharacters: minUpperCaseCharacters,
Expand All @@ -46,6 +48,9 @@ func NewPasswordPolicy(minCharacters, minLowerCaseCharacters, minUpperCaseCharac

// Validate implements a password validation regarding the policy
func (s Policies) Validate(str string) error {
if s.disabled {
return nil
}
var allErr error
if !utf8.ValidString(str) {
return fmt.Errorf("the password contains invalid characters")
Expand Down
2 changes: 2 additions & 0 deletions pkg/password/password_policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func TestPolicies_Validate(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := NewPasswordPolicy(
false,
tt.fields.minCharacters,
tt.fields.minLowerCaseCharacters,
tt.fields.minUpperCaseCharacters,
Expand Down Expand Up @@ -143,6 +144,7 @@ func TestPasswordPolicies_Count(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
i := NewPasswordPolicy(
false,
tt.fields.wantCharacters,
tt.fields.wantLowerCaseCharacters,
tt.fields.wantUpperCaseCharacters,
Expand Down

0 comments on commit ff56cb3

Please sign in to comment.