package main import ( "net/http" goaltcha "github.com/k42-software/go-altcha" altchahttp "github.com/k42-software/go-altcha/http" ) func serveAltchaJS(w http.ResponseWriter, r *http.Request) { altchahttp.ServeJavascript(w, r) } func serveAltchaChallenge(w http.ResponseWriter, r *http.Request) { challenge := goaltcha.NewChallenge() w.Header().Set("Content-Type", "application/json") w.Header().Set("Cache-Control", "private, no-cache, no-store, must-revalidate") _, _ = w.Write([]byte(challenge.Encode())) } func validateAltcha(r *http.Request) bool { encoded := r.PostFormValue("altcha") if encoded == "" { return false } return goaltcha.ValidateResponse(encoded, true) }