This commit is contained in:
2026-08-16 20:58:57 +08:00
parent a85477be80
commit a9e1f9e6f8
42 changed files with 1569 additions and 156 deletions
+4 -1
View File
@@ -93,7 +93,10 @@ func (uc *APIUsecase) SyncAPIs(ctx context.Context, routes []*API) (*APISyncDiff
}
for _, item := range stored {
storedKey := key(item)
if routeSet[storedKey] == nil && !ignoreSet[storedKey] {
// Ignoring an API removes it from the in-memory route comparison. If it
// already exists in sys_apis, the reference implementation therefore
// returns it in deleteApis while also returning it in ignoreApis.
if routeSet[storedKey] == nil {
diff.Deleted = append(diff.Deleted, item)
}
}
+17 -10
View File
@@ -3,10 +3,13 @@ package biz
import (
"context"
"errors"
"fmt"
"strconv"
"strings"
"sync"
"time"
"unicode"
"unicode/utf8"
)
type SecurityConfig struct {
@@ -90,33 +93,37 @@ func (uc *SecurityUsecase) Current(ctx context.Context) (*SecurityConfig, error)
}
func (uc *SecurityUsecase) ValidatePassword(value *SecurityConfig, password string) error {
if len([]rune(password)) < value.PwdMinLength {
return errors.New("密码长度不足")
if value.PwdMinLength > 0 && utf8.RuneCountInString(password) < value.PwdMinLength {
return fmt.Errorf("密码长度不能少于 %d 位", value.PwdMinLength)
}
hasUpper, hasLower, hasDigit, hasSpecial := false, false, false, false
for _, ch := range password {
switch {
case ch >= 'A' && ch <= 'Z':
case unicode.IsUpper(ch):
hasUpper = true
case ch >= 'a' && ch <= 'z':
case unicode.IsLower(ch):
hasLower = true
case ch >= '0' && ch <= '9':
case unicode.IsDigit(ch):
hasDigit = true
default:
case unicode.IsPunct(ch) || unicode.IsSymbol(ch):
hasSpecial = true
}
}
missing := make([]string, 0, 4)
if value.PwdRequireUpper && !hasUpper {
return errors.New("密码必须包含大写字母")
missing = append(missing, "大写字母")
}
if value.PwdRequireLower && !hasLower {
return errors.New("密码必须包含小写字母")
missing = append(missing, "小写字母")
}
if value.PwdRequireDigit && !hasDigit {
return errors.New("密码必须包含数字")
missing = append(missing, "数字")
}
if value.PwdRequireSpecial && !hasSpecial {
return errors.New("密码必须包含特殊字符")
missing = append(missing, "特殊字符")
}
if len(missing) > 0 {
return fmt.Errorf("密码必须包含%s", strings.Join(missing, "、"))
}
return nil
}