diff --git a/internal/api/handler/prosody_hdl.go b/internal/api/handler/prosody_hdl.go index 76102c6..a39f214 100644 --- a/internal/api/handler/prosody_hdl.go +++ b/internal/api/handler/prosody_hdl.go @@ -2,6 +2,7 @@ package handler import ( "fmt" + "log" "gitea.urkob.com/urko/prosody-password/internal/services/fail2ban" "gitea.urkob.com/urko/prosody-password/internal/services/prosody" @@ -33,6 +34,7 @@ func (handler ProsodyHandler) Post(c *fiber.Ctx) error { } if err := handler.prosodyService.ChangePassword(req.User, req.CurrentPassword, req.NewPassword); err != nil { + log.Println("c.IPs()", c.IPs()) for _, ip := range c.IPs() { handler.fail2banSrv.FailedAttempt(ip) } diff --git a/internal/services/prosody/account.go b/internal/services/prosody/account.go index 531f87d..05d962c 100644 --- a/internal/services/prosody/account.go +++ b/internal/services/prosody/account.go @@ -10,7 +10,7 @@ import ( type account struct { Salt string `prosody:"salt"` StoredKey string `prosody:"stored_key"` - IterationCount int `prosody:"iteration_count"` + IterationCount string `prosody:"iteration_count"` } func (acc *account) unmarshal(data map[string]interface{}) { diff --git a/internal/services/prosody/change_password.go b/internal/services/prosody/change_password.go index 72afe9e..b4b6bfd 100644 --- a/internal/services/prosody/change_password.go +++ b/internal/services/prosody/change_password.go @@ -8,6 +8,7 @@ import ( "fmt" "log" "os/exec" + "strconv" "github.com/xdg-go/pbkdf2" ) @@ -18,7 +19,12 @@ func (p *Prosody) ChangePassword(user string, currentPwd string, newPwd string) return fmt.Errorf("p.loadAccount %w", err) } - storedKey, err := hashPassword(currentPwd, acc.Salt, acc.IterationCount) + iterationCount, err := strconv.Atoi(acc.IterationCount) + if err != nil { + return fmt.Errorf("strconv.Atoi %w", err) + } + + storedKey, err := hashPassword(currentPwd, acc.Salt, iterationCount) if err != nil { return fmt.Errorf("hashPassword: %w", err) }