Skip to content

Latest commit

 

History

History
36 lines (28 loc) · 641 Bytes

README.md

File metadata and controls

36 lines (28 loc) · 641 Bytes

Go CSRF Token Generator and Validator

GoDoc

Import

import "github.com/jor-go/csrf"

Usage

package main

import (
	"github.com/jor-go/csrf"
	"fmt"
	"time"
)


func main() {
	// Set Secret and Token Duration
	csrf.Secret = "cool-secret"
	csrf.MaxTokenAge = 12 * time.Hour
	
	// Get Session ID
	sessionID := "1234"

	// Generate Token
	token := csrf.CreateToken(sessionID)
	fmt.Println(token)

	// Validate Token
	isValid := csrf.ValidToken(token, sessionID)
	fmt.Println("Token is Valid:", isValid)
}