csrf/auth_make.go

19 lines
481 B
Go
Raw Normal View History

2025-01-12 11:40:15 +00:00
package csrf
import (
"crypto/md5"
"fmt"
"strconv"
"time"
)
// a CSRF key is valid for the current time, route, and user.
func (c CSRF) AuthMake(userID string, routeName string) string {
// h := sha256.New()
// h.Write([]byte(userID + routeName + CSRFKey + strconv.Itoa(time.Now().Hour())))
// return fmt.Sprintf("%x", h.Sum(nil))
minfactor := strconv.Itoa(time.Now().Hour())
res := fmt.Sprintf("%x", md5.Sum([]byte(userID+routeName+c.CSRFKey+minfactor)))
return res
}