From d94cb759c827ff9331504d41a5d93c9e4e74b73f Mon Sep 17 00:00:00 2001 From: WithoutPants <53250216+WithoutPants@users.noreply.github.com> Date: Mon, 29 Jul 2019 16:49:39 +1000 Subject: [PATCH] Don't hash blank password. Treat blank username/pw as no credentials --- pkg/manager/config/config.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/manager/config/config.go b/pkg/manager/config/config.go index 030d8f7d6..04ac9042b 100644 --- a/pkg/manager/config/config.go +++ b/pkg/manager/config/config.go @@ -24,7 +24,12 @@ func Set(key string, value interface{}) { } func SetPassword(value string) { - Set(Password, hashPassword(value)) + // if blank, don't bother hashing; we want it to be blank + if value == "" { + Set(Password, "") + } else { + Set(Password, hashPassword(value)) + } } func Write() error { @@ -76,7 +81,14 @@ func GetCredentials() (string, string) { } func HasCredentials() bool { - return viper.IsSet(Username) && viper.IsSet(Password) + if !viper.IsSet(Username) || !viper.IsSet(Password) { + return false + } + + username := GetUsername() + pwHash := GetPasswordHash() + + return username != "" && pwHash != "" } func hashPassword(password string) string {