From 309acc4859c417c6314f0cb60f1f0c68acd12c80 Mon Sep 17 00:00:00 2001 From: kelmith Date: Thu, 23 Oct 2025 00:33:46 +0530 Subject: [PATCH 1/2] generate random six alphanumeric --- handlers/bounty.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/handlers/bounty.go b/handlers/bounty.go index 8857ce9e6..90b9a8bd8 100644 --- a/handlers/bounty.go +++ b/handlers/bounty.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "log" + "math/rand" "net/http" "net/url" "os" @@ -625,10 +626,15 @@ func (h *bountyHandler) CreateOrEditBounty(w http.ResponseWriter, r *http.Reques json.NewEncoder(w).Encode(b) } +const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + func generateUnlockCode() string { - // rand.Seed(time.Now().UnixNano()) - // return fmt.Sprintf("%06d", rand.Intn(1000000)) - return xid.New().String() + length := 36 + result := make([]byte, length) + for i := range result { + result[i] = letters[rand.Intn(len(letters))] + } + return string(result) } // DeleteBounty godoc From e002a7c90a32e6c918cf337b162a2ffc5e988978 Mon Sep 17 00:00:00 2001 From: kelmith Date: Thu, 23 Oct 2025 00:38:09 +0530 Subject: [PATCH 2/2] 36 to 6 --- handlers/bounty.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlers/bounty.go b/handlers/bounty.go index 90b9a8bd8..2a03eed0b 100644 --- a/handlers/bounty.go +++ b/handlers/bounty.go @@ -629,7 +629,7 @@ func (h *bountyHandler) CreateOrEditBounty(w http.ResponseWriter, r *http.Reques const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" func generateUnlockCode() string { - length := 36 + length := 6 result := make([]byte, length) for i := range result { result[i] = letters[rand.Intn(len(letters))]