login
This commit is contained in:
parent
eccd383c1c
commit
e2d80af81d
3 changed files with 18 additions and 4 deletions
|
|
@ -2,6 +2,8 @@ package server
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
"crypto/subtle"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -18,5 +20,11 @@ func userIsAuthenticated(req *http.Request, username, password string) bool {
|
|||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue