From 59758b2c062b1b47ccd8ca4770b2f83798aa1754 Mon Sep 17 00:00:00 2001 From: Manuel Bovo Date: Tue, 22 Aug 2017 10:58:36 +0200 Subject: [PATCH] Using map for multiple users/pass #33 --- api/basicauth.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/api/basicauth.go b/api/basicauth.go index 0d1f57d..d94e1e1 100644 --- a/api/basicauth.go +++ b/api/basicauth.go @@ -7,10 +7,9 @@ import ( ) type AuthConfig struct { - AuthEnabled bool `split_words:"true" default:"false"` - AuthUser string `split_words:"true" default:"orbiter"` - AuthPass string `split_words:"true" default:"orbiter"` - AuthRealm string `split_words:"true" default:"Restricted"` + AuthEnabled bool `split_words:"true" default:"false"` + AuthRealm string `split_words:"true" default:"Restricted"` + AuthCredential map[string]string `split_words:"true" default:"orbiter:orbiter"` } func wrap(h http.HandlerFunc, funx ...func(http.HandlerFunc) http.HandlerFunc) http.HandlerFunc { @@ -39,7 +38,7 @@ func basicAuth(h http.HandlerFunc) http.HandlerFunc { return } - if ac.AuthUser != u || ac.AuthPass != p { + if ac.AuthCredential[u] != p { logrus.Warnf("Invalid username or password for user %s", u) w.WriteHeader(401) w.Write([]byte("Invalid username or password"))