From 28a58303f02acc11e801a1ef5a85c3615c9b7b56 Mon Sep 17 00:00:00 2001 From: kolaente Date: Fri, 13 Dec 2024 20:46:36 +0100 Subject: [PATCH] fix(auth): convert to int when failed password value is not int Resolves https://github.com/go-vikunja/vikunja/issues/377 --- pkg/user/user.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pkg/user/user.go b/pkg/user/user.go index 3240a485a..e18558532 100644 --- a/pkg/user/user.go +++ b/pkg/user/user.go @@ -372,10 +372,23 @@ func handleFailedPassword(user *User) { a, _, err := keyvalue.Get(key) if err != nil { - log.Errorf("Could get failed password attempts for user %d: %s", user.ID, err) + log.Errorf("Could not get failed password attempts for user %d: %s", user.ID, err) return } - attempts := a.(int64) + attempts, ok := a.(int64) + if !ok { + attemptsStr, ok := a.(string) + if !ok { + log.Errorf("Unexpected type for failed password attempts: %v", a) + return + } + var err error + attempts, err = strconv.ParseInt(attemptsStr, 10, 64) + if err != nil { + log.Errorf("Could not convert failed password attempts to int64: %v, value: %s", err, attemptsStr) + return + } + } if attempts != 3 { return }