aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/auth/session.go
diff options
context:
space:
mode:
Diffstat (limited to 'backend/auth/session.go')
-rw-r--r--backend/auth/session.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/backend/auth/session.go b/backend/auth/session.go
new file mode 100644
index 0000000..a0d5aa4
--- /dev/null
+++ b/backend/auth/session.go
@@ -0,0 +1,21 @@
+package auth
+
+import (
+ "crypto/rand"
+ "crypto/sha256"
+ "encoding/hex"
+ "fmt"
+)
+
+func GenerateSessionID() (string, error) {
+ b := make([]byte, 32)
+ if _, err := rand.Read(b); err != nil {
+ return "", fmt.Errorf("generate session ID: %w", err)
+ }
+ return hex.EncodeToString(b), nil
+}
+
+func HashSessionID(raw string) string {
+ h := sha256.Sum256([]byte(raw))
+ return hex.EncodeToString(h[:])
+}