jeessy2/ddns-go · error

异常信息: %s

Error message

异常信息: %s

What it means

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.

Source

Thrown at config/config.go:229

	conf.SaveConfig()
	util.Log("用户名 %s 的密码已重置成功! 请重启ddns-go", conf.Username)
}

// CheckPassword 检查密码
func (conf *Config) CheckPassword(newPassword string) (hashedPwd string, err error) {
	var minEntropyBits float64 = 30
	if conf.NotAllowWanAccess {
		minEntropyBits = 25
	}
	err = passwordvalidator.Validate(newPassword, minEntropyBits)
	if err != nil {
		return "", errors.New(util.LogStr("密码不安全!尝试使用更复杂的密码"))
	}

	// 加密密码
	hashedPwd, err = util.HashPassword(newPassword)
	if err != nil {
		return "", errors.New(util.LogStr("异常信息: %s", err.Error()))
	}
	return
}

func (conf *DnsConfig) getIpv4AddrFromInterface() string {
	ipv4, _, err := GetNetInterface()
	if err != nil {
		util.Log("从网卡获得IPv4失败")
		return ""
	}

	for _, netInterface := range ipv4 {
		if netInterface.Name == conf.Ipv4.NetInterface && len(netInterface.Address) > 0 {
			return netInterface.Address[0]
		}
	}

	util.Log("从网卡中获得IPv4失败! 网卡名: %s", conf.Ipv4.NetInterface)

View on GitHub (pinned to 5874c2e666)

Solutions

  1. Inspect the wrapped underlying error (the %s content) to see the actual HashPassword failure
  2. Verify HashPassword's inputs and cost parameters are valid for the hashing library in use
  3. Rebuild/reinstall the binary and confirm the hashing library version is compatible
  4. Add unit tests around HashPassword to catch regressions

Example fix

// before
hashedPwd, err = util.HashPassword(newPassword)
if err != nil {
  return "", errors.New(util.LogStr("异常信息: %s", err.Error()))
}
// after
hashedPwd, err = util.HashPassword(newPassword)
if err != nil {
  return "", fmt.Errorf("密码哈希失败: %w", err) // keep cause, clearer context
}
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure input is non-empty before hashing
if newPassword == "" {
  return errors.New("新密码不能为空")
}

Type guard

null

Try / catch

hashedPwd, err = util.HashPassword(newPassword)
if err != nil {
  log.Printf("HashPassword failed: %v", err) // keep the root cause visible
  return "", fmt.Errorf("密码哈希失败: %w", err)
}

Prevention

When it happens

Trigger: ResetPassword -> CheckPassword -> util.HashPassword returns an error, e.g. bcrypt/argon2 cost parameter out of range, invalid hash input, or crypto library internal failure.

Common situations: 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.

Related errors


AI-assisted analysis of jeessy2/ddns-go@5874c2e666 (2026-09-03). Data as JSON: /api/errors/1bbe557cb94de205. Report an issue: GitHub.