From af542e339e5a611d2a1b5876450bee841b577640 Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Thu, 5 May 2022 10:05:40 -0700 Subject: removed redis dependency --- util/key.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'util/key.go') diff --git a/util/key.go b/util/key.go index 458d7c0..cd8662a 100644 --- a/util/key.go +++ b/util/key.go @@ -4,7 +4,11 @@ import ( "crypto/sha512" "encoding/hex" "math/rand" + "os" "strings" + + "github.com/FChannel0/FChannel-Server/config" + "github.com/gofiber/fiber/v2/middleware/encryptcookie" ) const domain = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" @@ -34,3 +38,21 @@ func RandomID(size int) string { return newID.String() } + +func GetCookieKey() (string, error) { + if config.CookieKey == "" { + var file *os.File + var err error + + if file, err = os.OpenFile("config/config-init", os.O_APPEND|os.O_WRONLY, 0644); err != nil { + return "", err + } + + defer file.Close() + + config.CookieKey = encryptcookie.GenerateKey() + file.WriteString("cookiekey:" + config.CookieKey) + } + + return config.CookieKey, nil +} -- cgit v1.2.3