mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-10-26 00:01:11 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user