更新认证令牌策略

This commit is contained in:
2026-08-01 18:52:41 +08:00
parent c8693a4f0e
commit ccdd5b0725
+8 -9
View File
@@ -61,19 +61,18 @@ func ValidatePassword(pwd string) bool {
if len(pwd) < 8 { if len(pwd) < 8 {
return false return false
} }
var hasUpper, hasLower, hasDigit, hasSpecial bool var hasUpper, hasLower, hasDigit bool
for _, ch := range pwd { for _, ch := range pwd {
if ch >= 'A' && ch <= 'Z' { switch {
case ch >= 'A' && ch <= 'Z':
hasUpper = true hasUpper = true
} else if ch >= 'a' && ch <= 'z' { case ch >= 'a' && ch <= 'z':
hasLower = true hasLower = true
} else if ch >= '0' && ch <= '9' { case ch >= '0' && ch <= '9':
hasDigit = true hasDigit = true
} else if strings.ContainsAny(string(ch), "!@#$%^&*()_+-=[]{}|;:,.<>?") {
hasSpecial = true
} }
} }
return hasUpper && hasLower && hasDigit && hasSpecial return hasUpper && hasLower && hasDigit
} }
func InitAdminUser() { func InitAdminUser() {
@@ -93,7 +92,7 @@ func InitAdminUser() {
username = "admin" username = "admin"
} }
for { for {
log.Print("密码 (至少8位,含大小写、数字、特殊字符): ") log.Print("密码 (至少8位,含大小写、数字): ")
var password string var password string
fmt.Scanln(&password) fmt.Scanln(&password)
if ValidatePassword(password) { if ValidatePassword(password) {
@@ -111,7 +110,7 @@ func InitAdminUser() {
break break
} else { } else {
log.Println("❌ 密码不符合复杂度要求,请重新输入") log.Println("❌ 密码不符合复杂度要求,请重新输入")
log.Println(" 要求: 至少8位,包含大小写字母、数字和特殊字符") log.Println(" 要求: 至少8位,包含大小写字母、数字")
} }
} }
} }