mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	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
This commit is contained in:
		@@ -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"))
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user