mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-24 00:33:14 +00:00
31 lines
658 B
Go
31 lines
658 B
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"crypto/subtle"
|
|
"time"
|
|
)
|
|
|
|
|
|
func userIsAuthenticated(req *http.Request, username, password string) bool {
|
|
cookie, _ := req.Cookie("auth")
|
|
if cookie == nil {
|
|
return false
|
|
}
|
|
// TODO: change to something sane
|
|
if cookie.Value != username {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func userAuthenticate(rw http.ResponseWriter, username, password string) {
|
|
expires := time.Now().Add(time.Hour * 24 * 7) // 1 week
|
|
cookie := http.Cookie{Name: "auth", Value: username, Expires: expires}
|
|
http.SetCookie(rw, &cookie)
|
|
}
|
|
|
|
func safeCompare(p1, p2 string) bool {
|
|
return subtle.ConstantTimeCompare([]byte(p1), []byte(p2)) == 1
|
|
}
|