jlelse
/
kis3
Archived
1
Fork 0
This repository has been archived on 2021-01-04. You can view files and clone it, but cannot push or open issues or pull requests.
kis3/helpers/basicAuth.go

15 lines
401 B
Go

package helpers
import "net/http"
func CheckAuth(w http.ResponseWriter, r *http.Request, username string, password string) (ok bool) {
w.Header().Set("WWW-Authenticate", `Basic realm="Authentication required"`)
rUsername, rPassword, rOk := r.BasicAuth()
if rOk && rUsername == username && rPassword == password {
return true
} else {
http.Error(w, "Not authorized", 401)
return false
}
}