2022-06-03 04:00:13 +00:00
|
|
|
package security
|
|
|
|
|
|
|
|
import (
|
|
|
|
portainer "github.com/portainer/portainer/api"
|
2022-09-16 16:18:44 +00:00
|
|
|
|
|
|
|
"github.com/rs/zerolog/log"
|
2022-06-03 04:00:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type PasswordStrengthChecker interface {
|
|
|
|
Check(password string) bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type passwordStrengthChecker struct {
|
|
|
|
settings settingsService
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPasswordStrengthChecker(settings settingsService) *passwordStrengthChecker {
|
|
|
|
return &passwordStrengthChecker{
|
|
|
|
settings: settings,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check returns true if the password is strong enough
|
|
|
|
func (c *passwordStrengthChecker) Check(password string) bool {
|
|
|
|
s, err := c.settings.Settings()
|
|
|
|
if err != nil {
|
2022-09-16 16:18:44 +00:00
|
|
|
log.Warn().Err(err).Msg("failed to fetch Portainer settings to validate user password")
|
|
|
|
|
2022-06-03 04:00:13 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return len(password) >= s.InternalAuthSettings.RequiredPasswordLength
|
|
|
|
}
|
|
|
|
|
|
|
|
type settingsService interface {
|
|
|
|
Settings() (*portainer.Settings, error)
|
|
|
|
}
|