Socialify

Folder ..

Viewing tokens.go
15 lines (13 loc) • 273.0 B

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
package utils

import (
	"crypto/rand"
	"encoding/base64"
)

// GenerateToken creates a secure random token for CSRF
func GenerateToken() string {
	b := make([]byte, 32)
	if _, err := rand.Read(b); err != nil {
		return ""
	}
	return base64.URLEncoding.EncodeToString(b)
}