From 426a72f8142327793bdd5719bb9e3548cec4b0a3 Mon Sep 17 00:00:00 2001 From: Amolith Date: Sat, 27 Sep 2025 13:20:50 -0600 Subject: [PATCH] chore: resolve magic number lint errors Co-Authored-By: Crush --- project/project.go | 6 +++++- users/users.go | 12 ++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/project/project.go b/project/project.go index f8b21c7deb8d1417d4fb4c26c841340264ecb383..073e2303ebc4bc9025b51c89d6b1576b8514ab3c 100644 --- a/project/project.go +++ b/project/project.go @@ -21,6 +21,10 @@ import ( "github.com/unascribed/FlexVer/go/flexver" ) +const ( + refreshInterval = 3600 * time.Second +) + type Project struct { ID string URL string @@ -239,7 +243,7 @@ func RefreshLoop(dbConn *sql.DB, mu *sync.Mutex, interval int, manualRefresh, re case <-ticker.C: projects = fetch() case <-*manualRefresh: - ticker.Reset(time.Second * 3600) + ticker.Reset(refreshInterval) projects = fetch() case <-*req: diff --git a/users/users.go b/users/users.go index 1945689f4e0278adfb0d85c005224f8ce5dc20a1..a8a3923bfe9b0bd5d7345ac9a3d3603dbab056cd 100644 --- a/users/users.go +++ b/users/users.go @@ -14,6 +14,14 @@ import ( "golang.org/x/crypto/argon2" ) +const ( + argon2Time = 2 + saltLength = 16 + argon2KeyLen = 64 + argon2Memory = 64 * 1024 + argon2Threads = 4 +) + // argonHash accepts two strings for the user's password and a random salt, // hashes the password using the salt, and returns the hash as a base64-encoded // string. @@ -23,13 +31,13 @@ func argonHash(password, salt string) (string, error) { return "", err } - return base64.StdEncoding.EncodeToString(argon2.IDKey([]byte(password), decodedSalt, 2, 64*1024, 4, 64)), nil + return base64.StdEncoding.EncodeToString(argon2.IDKey([]byte(password), decodedSalt, argon2Time, argon2Memory, argon2Threads, argon2KeyLen)), nil } // generateSalt generates a random salt and returns it as a base64-encoded // string. func generateSalt() (string, error) { - salt := make([]byte, 16) + salt := make([]byte, saltLength) _, err := rand.Read(salt) if err != nil {