summaryrefslogtreecommitdiffstats
path: root/modules/setting/setting.go
diff options
context:
space:
mode:
authorguillep2k <18600385+guillep2k@users.noreply.github.com>2019-10-16 00:09:58 -0300
committerLunny Xiao <xiaolunwen@gmail.com>2019-10-16 11:09:58 +0800
commit31655aabfc397db203d39b468cad1ecbdc1879db (patch)
tree07bb7133bb4ff74a96abf4c3ab1587e27fdf1298 /modules/setting/setting.go
parent66e99d722a71d12b81264bc3577b85febe40e49e (diff)
downloadgitea-31655aabfc397db203d39b468cad1ecbdc1879db.tar.gz
gitea-31655aabfc397db203d39b468cad1ecbdc1879db.zip
Fix password complexity regex for special characters (on master) (#8525)
* Fix extra space * Fix regular expression * Fix error template name * Simplify check code, fix default values, add test * Fix router tests * Fix fmt * Fix setting and lint * Move cleaning up code to test, improve comments * Tidy up variable declaration
Diffstat (limited to 'modules/setting/setting.go')
-rw-r--r--modules/setting/setting.go24
1 files changed, 6 insertions, 18 deletions
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index afcb943d00..d05c52fea0 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -149,7 +149,7 @@ var (
MinPasswordLength int
ImportLocalPaths bool
DisableGitHooks bool
- PasswordComplexity map[string]string
+ PasswordComplexity []string
PasswordHashAlgo string
// UI settings
@@ -781,26 +781,14 @@ func NewContext() {
InternalToken = loadInternalToken(sec)
- var dictPC = map[string]string{
- "lower": "[a-z]+",
- "upper": "[A-Z]+",
- "digit": "[0-9]+",
- "spec": `][ !"#$%&'()*+,./:;<=>?@\\^_{|}~` + "`-",
- }
- PasswordComplexity = make(map[string]string)
cfgdata := sec.Key("PASSWORD_COMPLEXITY").Strings(",")
- for _, y := range cfgdata {
- ts := strings.TrimSpace(y)
- for a := range dictPC {
- if strings.ToLower(ts) == a {
- PasswordComplexity[ts] = dictPC[ts]
- break
- }
+ PasswordComplexity = make([]string, 0, len(cfgdata))
+ for _, name := range cfgdata {
+ name := strings.ToLower(strings.Trim(name, `"`))
+ if name != "" {
+ PasswordComplexity = append(PasswordComplexity, name)
}
}
- if len(PasswordComplexity) == 0 {
- PasswordComplexity = dictPC
- }
sec = Cfg.Section("attachment")
AttachmentPath = sec.Key("PATH").MustString(path.Join(AppDataPath, "attachments"))