1
0
mirror of https://github.com/gilbertchen/duplicacy synced 2025-12-15 15:53:26 +00:00

When resetPassword is true, the entered password should be the same as that in environment or preference

This commit is contained in:
Gilbert Chen
2017-09-25 21:31:35 -04:00
parent 923cd0aa63
commit 5031ae15d0

View File

@@ -182,12 +182,12 @@ func GetPasswordFromPreference(preference Preference, passwordType string) strin
// (i.e., preference.Name) in the key, so the key name should really be passwordType rather // (i.e., preference.Name) in the key, so the key name should really be passwordType rather
// than passwordID; we're using passwordID here only for backward compatibility // than passwordID; we're using passwordID here only for backward compatibility
if len(preference.Keys) > 0 && len(preference.Keys[passwordID]) > 0 { if len(preference.Keys) > 0 && len(preference.Keys[passwordID]) > 0 {
LOG_DEBUG("PASSWORD_KEYCHAIN", "Reading %s from preferences", passwordID) LOG_DEBUG("PASSWORD_PREFERENCE", "Reading %s from preferences", passwordID)
return preference.Keys[passwordID] return preference.Keys[passwordID]
} }
if len(preference.Keys) > 0 && len(preference.Keys[passwordType]) > 0 { if len(preference.Keys) > 0 && len(preference.Keys[passwordType]) > 0 {
LOG_DEBUG("PASSWORD_KEYCHAIN", "Reading %s from preferences", passwordType) LOG_DEBUG("PASSWORD_PREFERENCE", "Reading %s from preferences", passwordType)
return preference.Keys[passwordType] return preference.Keys[passwordType]
} }
@@ -198,9 +198,10 @@ func GetPasswordFromPreference(preference Preference, passwordType string) strin
func GetPassword(preference Preference, passwordType string, prompt string, func GetPassword(preference Preference, passwordType string, prompt string,
showPassword bool, resetPassword bool) string { showPassword bool, resetPassword bool) string {
passwordID := passwordType passwordID := passwordType
password := GetPasswordFromPreference(preference, passwordType)
if password != "" { preferencePassword := GetPasswordFromPreference(preference, passwordType)
return password if preferencePassword != "" && !resetPassword {
return preferencePassword
} }
if preference.Name != "default" { if preference.Name != "default" {
@@ -212,6 +213,7 @@ func GetPassword(preference Preference, passwordType string, prompt string,
} else { } else {
password := keyringGet(passwordID) password := keyringGet(passwordID)
if password != "" { if password != "" {
LOG_DEBUG("PASSWORD_KEYCHAIN", "Reading %s from keychain/keyring", passwordType)
return password return password
} }
@@ -222,7 +224,7 @@ func GetPassword(preference Preference, passwordType string, prompt string,
} }
password = "" password := ""
fmt.Printf("%s", prompt) fmt.Printf("%s", prompt)
if showPassword { if showPassword {
scanner := bufio.NewScanner(os.Stdin) scanner := bufio.NewScanner(os.Stdin)
@@ -237,6 +239,11 @@ func GetPassword(preference Preference, passwordType string, prompt string,
password = string(passwordInBytes) password = string(passwordInBytes)
} }
if resetPassword && preferencePassword != "" && preferencePassword != password {
LOG_ERROR("PASSWORD_MISMATCH", "The password entered is different from what is in the environment or preference")
return ""
}
return password return password
} }