From 24cbcef6205fb74fb238348c3fe3e08457bd50f9 Mon Sep 17 00:00:00 2001 From: Audrius Butkevicius Date: Sat, 13 Sep 2014 21:52:20 +0100 Subject: [PATCH] Send the real hash as part of the config (fixes #681) --- cmd/syncthing/gui.go | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go index e0afc7d3d..185964477 100644 --- a/cmd/syncthing/gui.go +++ b/cmd/syncthing/gui.go @@ -45,10 +45,6 @@ var ( eventSub *events.BufferedSubscription ) -const ( - unchangedPassword = "--password-unchanged--" -) - func init() { l.AddHandler(logger.LevelWarn, showGuiError) sub := events.Default.Subscribe(events.AllEvents) @@ -274,12 +270,8 @@ func restGetNodeStats(m *model.Model, w http.ResponseWriter, r *http.Request) { } func restGetConfig(w http.ResponseWriter, r *http.Request) { - encCfg := cfg - if encCfg.GUI.Password != "" { - encCfg.GUI.Password = unchangedPassword - } w.Header().Set("Content-Type", "application/json; charset=utf-8") - json.NewEncoder(w).Encode(encCfg) + json.NewEncoder(w).Encode(cfg) } func restPostConfig(m *model.Model, w http.ResponseWriter, r *http.Request) { @@ -290,18 +282,16 @@ func restPostConfig(m *model.Model, w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), 500) return } else { - if newCfg.GUI.Password == "" { - // Leave it empty - } else if newCfg.GUI.Password == unchangedPassword { - newCfg.GUI.Password = cfg.GUI.Password - } else { - hash, err := bcrypt.GenerateFromPassword([]byte(newCfg.GUI.Password), 0) - if err != nil { - l.Warnln("bcrypting password:", err) - http.Error(w, err.Error(), 500) - return - } else { - newCfg.GUI.Password = string(hash) + if newCfg.GUI.Password != cfg.GUI.Password { + if newCfg.GUI.Password != "" { + hash, err := bcrypt.GenerateFromPassword([]byte(newCfg.GUI.Password), 0) + if err != nil { + l.Warnln("bcrypting password:", err) + http.Error(w, err.Error(), 500) + return + } else { + newCfg.GUI.Password = string(hash) + } } }