diff options
author | David Lu <david.lu@hotmail.com> | 2016-07-06 18:54:54 -0400 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2016-07-06 14:54:54 -0800 |
commit | 683f7133190aa350cdd1ea2608c90fe5f47b35cd (patch) | |
tree | 3f1bcc19d3bc1a7dedd407c266ea63cdda5ed9c9 /utils | |
parent | 0c3c52b8d3a3503c35481a287ba27f626749503a (diff) | |
download | chat-683f7133190aa350cdd1ea2608c90fe5f47b35cd.tar.gz chat-683f7133190aa350cdd1ea2608c90fe5f47b35cd.tar.bz2 chat-683f7133190aa350cdd1ea2608c90fe5f47b35cd.zip |
PLT-1465 Added password requirements (#3489)
* Added password requirements
* added tweaks
* fixed error code
* removed http.StatusNotAcceptable
Diffstat (limited to 'utils')
-rw-r--r-- | utils/config.go | 8 | ||||
-rw-r--r-- | utils/license.go | 1 | ||||
-rw-r--r-- | utils/password.go | 64 |
3 files changed, 73 insertions, 0 deletions
diff --git a/utils/config.go b/utils/config.go index 1fbed5d7b..cbae0e2cb 100644 --- a/utils/config.go +++ b/utils/config.go @@ -288,6 +288,14 @@ func getClientConfig(c *model.Config) map[string]string { props["EnableSaml"] = strconv.FormatBool(*c.SamlSettings.Enable) props["SamlLoginButtonText"] = *c.SamlSettings.LoginButtonText } + + if *License.Features.PasswordRequirements { + props["PasswordMinimumLength"] = fmt.Sprintf("%v", *c.PasswordSettings.MinimumLength) + props["PasswordRequireLowercase"] = strconv.FormatBool(*c.PasswordSettings.Lowercase) + props["PasswordRequireUppercase"] = strconv.FormatBool(*c.PasswordSettings.Uppercase) + props["PasswordRequireNumber"] = strconv.FormatBool(*c.PasswordSettings.Number) + props["PasswordRequireSymbol"] = strconv.FormatBool(*c.PasswordSettings.Symbol) + } } return props diff --git a/utils/license.go b/utils/license.go index b80e1abc2..1b908a599 100644 --- a/utils/license.go +++ b/utils/license.go @@ -126,6 +126,7 @@ func getClientLicense(l *model.License) map[string]string { props["Compliance"] = strconv.FormatBool(*l.Features.Compliance) props["CustomBrand"] = strconv.FormatBool(*l.Features.CustomBrand) props["MHPNS"] = strconv.FormatBool(*l.Features.MHPNS) + props["PasswordRequirements"] = strconv.FormatBool(*l.Features.PasswordRequirements) props["IssuedAt"] = strconv.FormatInt(l.IssuedAt, 10) props["StartsAt"] = strconv.FormatInt(l.StartsAt, 10) props["ExpiresAt"] = strconv.FormatInt(l.ExpiresAt, 10) diff --git a/utils/password.go b/utils/password.go new file mode 100644 index 000000000..dc1d771b8 --- /dev/null +++ b/utils/password.go @@ -0,0 +1,64 @@ +// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package utils + +import ( + "github.com/mattermost/platform/model" + "strings" +) + +func IsPasswordValid(password string) *model.AppError { + id := "model.user.is_valid.pwd" + isError := false + min := model.PASSWORD_MINIMUM_LENGTH + + if IsLicensed && *License.Features.PasswordRequirements { + if len(password) < *Cfg.PasswordSettings.MinimumLength || len(password) > model.PASSWORD_MAXIMUM_LENGTH { + isError = true + } + + if *Cfg.PasswordSettings.Lowercase { + if !strings.ContainsAny(password, model.LOWERCASE_LETTERS) { + isError = true + } + + id = id + "_lowercase" + } + + if *Cfg.PasswordSettings.Uppercase { + if !strings.ContainsAny(password, model.UPPERCASE_LETTERS) { + isError = true + } + + id = id + "_uppercase" + } + + if *Cfg.PasswordSettings.Number { + if !strings.ContainsAny(password, model.NUMBERS) { + isError = true + } + + id = id + "_number" + } + + if *Cfg.PasswordSettings.Symbol { + if !strings.ContainsAny(password, model.SYMBOLS) { + isError = true + } + + id = id + "_symbol" + } + + min = *Cfg.PasswordSettings.MinimumLength + } else if len(password) > model.PASSWORD_MAXIMUM_LENGTH || len(password) < model.PASSWORD_MINIMUM_LENGTH { + isError = true + min = model.PASSWORD_MINIMUM_LENGTH + } + + if isError { + return model.NewLocAppError("User.IsValid", id+".app_error", map[string]interface{}{"Min": min}, "") + } + + return nil +} |