From bd435d1a13b7184ed92cf50cdb6829a01a0145e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C4=85tkowski?= Date: Fri, 5 Aug 2022 22:44:20 +0200 Subject: [PATCH] Improve authentication logs --- cmd/magneticow/main.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/magneticow/main.go b/cmd/magneticow/main.go index 5764e8c..63aa44f 100644 --- a/cmd/magneticow/main.go +++ b/cmd/magneticow/main.go @@ -274,13 +274,13 @@ func loadCred(cred string) error { reader := bufio.NewReader(file) for lineno := 1; true; lineno++ { line, err := reader.ReadBytes('\n') + zap.L().Debug("Credentials: " + string(line)) if err != nil { if err == io.EOF { break } return errors.Wrapf(err, "while reading line %d", lineno) } - line = line[:len(line)-1] // strip '\n' /* The following regex checks if the line satisfies the following conditions: @@ -297,7 +297,6 @@ func loadCred(cred string) error { if !re.Match(line) { return fmt.Errorf("on line %d: format should be: :, instead got: %s", lineno, line) } - tokens := bytes.Split(line, []byte(":")) opts.Credentials[string(tokens[0])] = tokens[1] } @@ -310,7 +309,7 @@ func loadCred(cred string) error { // // Most web browser display a dialog with something like: // -// The website says: "" +// The website says: "" // // Which is really stupid so you may want to set the realm to a message rather than // an actual realm. @@ -333,12 +332,14 @@ func BasicAuth(handler http.HandlerFunc, realm string) http.HandlerFunc { hashedPassword, ok := opts.Credentials[username] opts.CredentialsRWMutex.RUnlock() if !ok { // User not found + zap.L().Error("User \"" + string(username) + "\" not found!") authenticate(w, realm) return } if err := bcrypt.CompareHashAndPassword(hashedPassword, []byte(password)); err != nil { // Wrong password authenticate(w, realm) + zap.L().Error("Wrong password provided!") return }