Fix syntax

This commit is contained in:
ravenclaw900 2021-06-12 16:53:04 -05:00
parent 0d17cae66a
commit 80bb9de533

View File

@ -65,17 +65,15 @@ func (authMid *HTTPAuthMiddleware) Middleware(next http.Handler) http.Handler {
if (authMid.user == "" && authMid.passwd == "") || if (authMid.user == "" && authMid.passwd == "") ||
(hasAuth && reqUser == authMid.user && reqPasswd == authMid.passwd) { (hasAuth && reqUser == authMid.user && reqPasswd == authMid.passwd) {
next.ServeHTTP(w, r) next.ServeHTTP(w, r)
} } else if authMid.user == reqUser && authMid.passwd[:4] == "$2a$" {
else if (authMid.user == reqUser && authMid.passwd[:4] == "$2a$") { correct := bcrypt.CompareHashAndPassword([]byte(authMid.passwd), []byte(reqPasswd))
correct := bcrypt.CompareHashAndPassword([]byte(reqPasswd), []byte(authMid.passwd)) if correct == nil {
if (correct == nil) {
next.ServeHTTP(w, r) next.ServeHTTP(w, r)
} else { } else {
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`) w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
} }
} } else {
else {
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`) w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) 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 == "") || if (user == "" && passwd == "") ||
(hasAuth && reqUser == user && reqPasswd == passwd) { (hasAuth && reqUser == user && reqPasswd == passwd) {
h.ServeHTTP(w, r) h.ServeHTTP(w, r)
} } else if user == reqUser && passwd[:4] == "$2a$" {
else if (user == reqUser && authMid.passwd[:4] == "$2a$") { correct := bcrypt.CompareHashAndPassword([]byte(passwd), []byte(reqPasswd))
correct := bcrypt.CompareHashAndPassword([]byte(reqPasswd), []byte(authMid.passwd)) if correct == nil {
if (correct == nil) {
h.ServeHTTP(w, r) h.ServeHTTP(w, r)
} else { } else {
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`) w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
} }
} } else {
else {
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`) w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
} }