11 func BasicAuth(r *http.Request) (username, password string, ok bool) {
12 tokens := strings.SplitN(r.Header.Get("Authorization"), " ", 2)
13 if len(tokens) != 2 || tokens[0] != "Basic" {
17 decoded, err := base64.StdEncoding.DecodeString(tokens[1])
22 userAndPass := strings.SplitN(string(decoded), ":", 2)
23 if len(userAndPass) != 2 {
27 return userAndPass[0], userAndPass[1], true