{"record":{"id":"1bbe557cb94de205","repo":"jeessy2/ddns-go","slug":"s","errorCode":null,"errorMessage":"异常信息: %s","messagePattern":"异常信息: %s","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/config.go","lineNumber":229,"sourceCode":"\tconf.SaveConfig()\n\tutil.Log(\"用户名 %s 的密码已重置成功! 请重启ddns-go\", conf.Username)\n}\n\n// CheckPassword 检查密码\nfunc (conf *Config) CheckPassword(newPassword string) (hashedPwd string, err error) {\n\tvar minEntropyBits float64 = 30\n\tif conf.NotAllowWanAccess {\n\t\tminEntropyBits = 25\n\t}\n\terr = passwordvalidator.Validate(newPassword, minEntropyBits)\n\tif err != nil {\n\t\treturn \"\", errors.New(util.LogStr(\"密码不安全！尝试使用更复杂的密码\"))\n\t}\n\n\t// 加密密码\n\thashedPwd, err = util.HashPassword(newPassword)\n\tif err != nil {\n\t\treturn \"\", errors.New(util.LogStr(\"异常信息: %s\", err.Error()))\n\t}\n\treturn\n}\n\nfunc (conf *DnsConfig) getIpv4AddrFromInterface() string {\n\tipv4, _, err := GetNetInterface()\n\tif err != nil {\n\t\tutil.Log(\"从网卡获得IPv4失败\")\n\t\treturn \"\"\n\t}\n\n\tfor _, netInterface := range ipv4 {\n\t\tif netInterface.Name == conf.Ipv4.NetInterface && len(netInterface.Address) > 0 {\n\t\t\treturn netInterface.Address[0]\n\t\t}\n\t}\n\n\tutil.Log(\"从网卡中获得IPv4失败! 网卡名: %s\", conf.Ipv4.NetInterface)","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/jeessy2/ddns-go/blob/5874c2e6667c69357ab95079421131104bd3fcae/config/config.go#L211-L247","documentation":"CheckPassword hashes the new password with util.HashPassword after validation succeeds. If hashing fails, ResetPassword returns this wrapped error with the underlying message embedded via %s. It indicates an internal failure in the password hashing routine, not a user input problem.","triggerScenarios":"ResetPassword -> CheckPassword -> util.HashPassword returns an error, e.g. bcrypt/argon2 cost parameter out of range, invalid hash input, or crypto library internal failure.","commonSituations":"Hashing library version upgrade changed the API; an invalid HashPassword implementation (e.g. cost > 31 for bcrypt); corrupted build or environment lacking required crypto support.","solutions":["Inspect the wrapped underlying error (the %s content) to see the actual HashPassword failure","Verify HashPassword's inputs and cost parameters are valid for the hashing library in use","Rebuild/reinstall the binary and confirm the hashing library version is compatible","Add unit tests around HashPassword to catch regressions"],"exampleFix":"// before\nhashedPwd, err = util.HashPassword(newPassword)\nif err != nil {\n  return \"\", errors.New(util.LogStr(\"异常信息: %s\", err.Error()))\n}\n// after\nhashedPwd, err = util.HashPassword(newPassword)\nif err != nil {\n  return \"\", fmt.Errorf(\"密码哈希失败: %w\", err) // keep cause, clearer context\n}","handlingStrategy":"try-catch","validationCode":"// ensure input is non-empty before hashing\nif newPassword == \"\" {\n  return errors.New(\"新密码不能为空\")\n}","typeGuard":"null","tryCatchPattern":"hashedPwd, err = util.HashPassword(newPassword)\nif err != nil {\n  log.Printf(\"HashPassword failed: %v\", err) // keep the root cause visible\n  return \"\", fmt.Errorf(\"密码哈希失败: %w\", err)\n}","preventionTips":["Unit-test HashPassword with typical and edge-case inputs","Keep hashing library versions pinned and reviewed on upgrade","Validate cost parameters are within library limits (bcrypt cost <= 31)","Never swallow the underlying error when wrapping — include it via %w"],"tags":["hashing","crypto","go"],"backgroundTag":"password-hash-failed","analyzedSha":"5874c2e6667c69357ab95079421131104bd3fcae","analyzedAt":"2026-09-03T15:41:16.799Z","contentChangedAt":"2026-09-03T15:41:16.799Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}