From 80bb9de5338995a90b6601b39924a815946e92f9 Mon Sep 17 00:00:00 2001 From: ravenclaw900 <50060110+ravenclaw900@users.noreply.github.com> Date: Sat, 12 Jun 2021 16:53:04 -0500 Subject: [PATCH] Fix syntax --- pkg/util/net/http.go | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/pkg/util/net/http.go b/pkg/util/net/http.go index de4d81a5..c68b78ab 100644 --- a/pkg/util/net/http.go +++ b/pkg/util/net/http.go @@ -65,17 +65,15 @@ func (authMid *HTTPAuthMiddleware) Middleware(next http.Handler) http.Handler { if (authMid.user == "" && authMid.passwd == "") || (hasAuth && reqUser == authMid.user && reqPasswd == authMid.passwd) { next.ServeHTTP(w, r) - } - else if (authMid.user == reqUser && authMid.passwd[:4] == "$2a$") { - correct := bcrypt.CompareHashAndPassword([]byte(reqPasswd), []byte(authMid.passwd)) - if (correct == nil) { + } else if authMid.user == reqUser && authMid.passwd[:4] == "$2a$" { + correct := bcrypt.CompareHashAndPassword([]byte(authMid.passwd), []byte(reqPasswd)) + if correct == nil { next.ServeHTTP(w, r) } else { w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`) http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) } - } - else { + } else { w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`) http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) } @@ -88,17 +86,15 @@ func HTTPBasicAuth(h http.HandlerFunc, user, passwd string) http.HandlerFunc { if (user == "" && passwd == "") || (hasAuth && reqUser == user && reqPasswd == passwd) { h.ServeHTTP(w, r) - } - else if (user == reqUser && authMid.passwd[:4] == "$2a$") { - correct := bcrypt.CompareHashAndPassword([]byte(reqPasswd), []byte(authMid.passwd)) - if (correct == nil) { + } else if user == reqUser && passwd[:4] == "$2a$" { + correct := bcrypt.CompareHashAndPassword([]byte(passwd), []byte(reqPasswd)) + if correct == nil { h.ServeHTTP(w, r) } else { w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`) http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) } - } - else { + } else { w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`) http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) }