fix: correct 1pctl password complexity validation (#14169)

* fix: correct 1pctl password complexity validation

`isValidPassword("newPassword")` passed a literal string and the condition was inverted, so the complexity check never ran. Extract the validation into a testable helper and cover both the enabled and disabled paths.

Refs #12640

* Delete core/cmd/server/cmd/update_test.go

---------

Co-authored-by: ssongliu <sloooop1x@gmail.com>
This commit is contained in:
Woolsen
2026-10-23 18:26:25 +08:00
committed by GitHub
co-authored by ssongliu
parent c925184bf6
commit 9295f4ef8a
+24 -7
View File
@@ -272,13 +272,11 @@ func password() {
return
}
complexSetting := getSettingByKey(db, "ComplexityVerification")
if complexSetting == constant.StatusEnable {
if isValidPassword("newPassword") {
fmt.Println("\n" + i18n.GetMsgByKeyForCmd("UpdatePasswordFormat"))
return
}
}
if len(newPassword) < 6 {
switch validatePassword(newPassword, complexSetting) {
case passwordTooWeak:
fmt.Println("\n" + i18n.GetMsgByKeyForCmd("UpdatePasswordFormat"))
return
case passwordTooShort:
fmt.Println(i18n.GetMsgByKeyForCmd("UpdatePasswordLen"))
return
}
@@ -377,6 +375,25 @@ func port() {
fmt.Println(std)
}
}
type passwordValidation int
const (
passwordValid passwordValidation = iota
passwordTooShort
passwordTooWeak
)
func validatePassword(password, complexitySetting string) passwordValidation {
if complexitySetting == constant.StatusEnable && !isValidPassword(password) {
return passwordTooWeak
}
if len(password) < 6 {
return passwordTooShort
}
return passwordValid
}
func isValidPassword(password string) bool {
numCount := 0
alphaCount := 0