forked from NYANDEV/forgejo
Fix password complexity regex for special characters (backport for v1.10.0) (#8524)
* 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:
parent
db0d4ffdc7
commit
595033f78e
9 changed files with 142 additions and 74 deletions
|
@ -146,7 +146,7 @@ var (
|
|||
MinPasswordLength int
|
||||
ImportLocalPaths bool
|
||||
DisableGitHooks bool
|
||||
PasswordComplexity map[string]string
|
||||
PasswordComplexity []string
|
||||
PasswordHashAlgo string
|
||||
|
||||
// UI settings
|
||||
|
@ -775,26 +775,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"))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue