mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
8659ba394d
Implement a password policy with visual feedback in the web portal. Co-authored-by: Manuel Nuñez <@mind-ar> Co-authored-by: James Elliott <james-d-elliott@users.noreply.github.com>
34 lines
1.3 KiB
Go
34 lines
1.3 KiB
Go
package validator
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/authelia/authelia/v4/internal/configuration/schema"
|
|
"github.com/authelia/authelia/v4/internal/utils"
|
|
)
|
|
|
|
// ValidatePasswordPolicy validates and update Password Policy configuration.
|
|
func ValidatePasswordPolicy(configuration *schema.PasswordPolicyConfiguration, validator *schema.StructValidator) {
|
|
if !utils.IsBoolCountLessThanN(1, true, configuration.Standard.Enabled, configuration.Zxcvbn.Enabled) {
|
|
validator.Push(errors.New("password_policy:only one password policy can be enabled at a time"))
|
|
}
|
|
|
|
if configuration.Standard.Enabled {
|
|
if configuration.Standard.MinLength == 0 {
|
|
configuration.Standard.MinLength = schema.DefaultPasswordPolicyConfiguration.Standard.MinLength
|
|
} else if configuration.Standard.MinLength < 0 {
|
|
validator.Push(errors.New("password_policy: min_length must be > 0"))
|
|
}
|
|
|
|
if configuration.Standard.MaxLength == 0 {
|
|
configuration.Standard.MaxLength = schema.DefaultPasswordPolicyConfiguration.Standard.MaxLength
|
|
}
|
|
} else if configuration.Zxcvbn.Enabled {
|
|
if configuration.Zxcvbn.MinScore == 0 {
|
|
configuration.Zxcvbn.MinScore = schema.DefaultPasswordPolicyConfiguration.Zxcvbn.MinScore
|
|
} else if configuration.Zxcvbn.MinScore < 0 || configuration.Zxcvbn.MinScore > 4 {
|
|
validator.Push(errors.New("min_score must be between 0 and 4"))
|
|
}
|
|
}
|
|
}
|