flipped-aurora/gin-vue-admin · warning
密码长度不能少于 %d 位
Error message
密码长度不能少于 %d 位
What it means
ValidatePasswordComplexity checks a password against the configured security policy (system.SysSecurityConfig). When cfg.PwdMinLength > 0 and the password has fewer UTF-8 runes than the minimum, it returns "密码长度不能少于 %d 位". It is a deliberate, user-facing validation error, not an internal fault.
Source
Thrown at server/utils/password_complexity.go:15
package utils
import (
"fmt"
"strings"
"unicode"
"unicode/utf8"
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
)
// ValidatePasswordComplexity 按安全配置校验密码复杂度 不满足返回可读错误
func ValidatePasswordComplexity(pwd string, cfg system.SysSecurityConfig) error {
if cfg.PwdMinLength > 0 && utf8.RuneCountInString(pwd) < cfg.PwdMinLength {
return fmt.Errorf("密码长度不能少于 %d 位", cfg.PwdMinLength)
}
var hasUpper, hasLower, hasDigit, hasSpecial bool
for _, r := range pwd {
switch {
case unicode.IsUpper(r):
hasUpper = true
case unicode.IsLower(r):
hasLower = true
case unicode.IsDigit(r):
hasDigit = true
case unicode.IsPunct(r) || unicode.IsSymbol(r):
hasSpecial = true
}
}
var missing []string
if cfg.PwdRequireUpper && !hasUpper {
missing = append(missing, "大写字母")
}View on GitHub (pinned to 3136500ef3)
Solutions
- Use a longer password meeting cfg.PwdMinLength characters.
- Check the configured PwdMinLength in system security settings and enforce the same minimum in the frontend form before submit.
- If the minimum is unnecessarily strict, adjust PwdMinLength in the security configuration.
Example fix
// before
ValidatePasswordComplexity("abc123", cfg) // fails when cfg.PwdMinLength = 8
// after
pwd := "Abcdef1!23"
if utf8.RuneCountInString(pwd) >= cfg.PwdMinLength {
_ = ValidatePasswordComplexity(pwd, cfg)
} Defensive patterns
Strategy: validation
Validate before calling
func pwdLongEnough(pwd string, cfg system.SysSecurityConfig) bool {
return cfg.PwdMinLength <= 0 || utf8.RuneCountInString(pwd) >= cfg.PwdMinLength
} Try / catch
if err := utils.ValidatePasswordComplexity(pwd, cfg); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest) // message is user-facing
return
} Prevention
- Enforce the same PwdMinLength in frontend form validation
- Show the configured minimum in the password hint text
- Notify users when the security policy tightens
- Never hardcode a length check different from the server config
When it happens
Trigger: Calling ValidatePasswordComplexity(pwd, cfg) (directly or via password change/create endpoints) where utf8.RuneCountInString(pwd) < cfg.PwdMinLength.
Common situations: Admin sets a stricter minimum (e.g. 8 or 12) in security config while users still submit short passwords; frontend not synced with backend's PwdMinLength; password change APIs called from scripts without the new policy.
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/6397564dea8c1169.
Report an issue: GitHub.