代码拉取完成,页面将自动刷新
package main
import (
"crypto/hmac"
"crypto/sha256"
"fmt"
"io"
"net/http"
)
func getCode(data string) string {
h := hmac.New(sha256.New, []byte("ourkey"))
io.WriteString(h, data)
return fmt.Sprintf("%x", h.Sum(nil))
}
func main() {
http.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
cookie, err := req.Cookie("session-id")
// cookie is not set
if err != nil {
//id, _ := uuid.NewV4()
cookie = &http.Cookie{
Name: "session-id",
}
}
if req.FormValue("email") != "" {
cookie.Value = req.FormValue("email")
}
code := getCode(cookie.Value)
cookie.Value = code + "|" + cookie.Value
// this doesn't run
// need more code added to work
// just shown for example of how to do auth with HMAC
http.SetCookie(res, cookie)
io.WriteString(res, `<!DOCTYPE html>
<html>
<body>
<form method="POST">
`+cookie.Value+`
<input type="email" name="email">
<input type="password" name="password">
<input type="submit">
</form>
</body>
</html>`)
})
http.ListenAndServe(":9000", nil)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。