Browse Source

Bug 1967 – Remembered password is forgotten after the first failed (re)connect, even if the failure did not involve the password

https://winscp.net/tracker/1967

Source commit: eb78a72b4684db71b0ad3737a7e81f86866475ae
Martin Prikryl 4 years ago
parent
commit
5c4b1a3a3c
2 changed files with 11 additions and 5 deletions
  1. 10 5
      source/core/Terminal.cpp
  2. 1 0
      source/core/Terminal.h

+ 10 - 5
source/core/Terminal.cpp

@@ -1250,6 +1250,7 @@ void __fastcall TTerminal::Open()
     DoInformation(L"", true, 1);
     try
     {
+      FRememberedPasswordUsed = false;
       try
       {
         ResetConnection();
@@ -1418,11 +1419,14 @@ void __fastcall TTerminal::Open()
           FFingerprintScannedSHA1 = SessionInfo.CertificateFingerprintSHA1;
           FFingerprintScannedMD5 = UnicodeString();
         }
-        // Particularly to prevent reusing a wrong client certificate passphrase
-        // in the next login attempt
-        FRememberedPassword = UnicodeString();
-        FRememberedPasswordKind = TPromptKind(-1);
-        FRememberedTunnelPassword = UnicodeString();
+        if (FRememberedPasswordUsed)
+        {
+          // Particularly to prevent reusing a wrong client certificate passphrase
+          // in the next login attempt
+          FRememberedPassword = UnicodeString();
+          FRememberedPasswordKind = TPromptKind(-1);
+          FRememberedTunnelPassword = UnicodeString();
+        }
         throw;
       }
     }
@@ -1738,6 +1742,7 @@ bool __fastcall TTerminal::DoPromptUser(TSessionData * /*Data*/, TPromptKind Kin
       {
         APassword = GetPasswordSource()->GetRememberedPassword();
       }
+      FRememberedPasswordUsed = true;
       Results->Strings[0] = APassword;
       if (!Results->Strings[0].IsEmpty())
       {

+ 1 - 0
source/core/Terminal.h

@@ -197,6 +197,7 @@ private:
   RawByteString FRememberedPassword;
   TPromptKind FRememberedPasswordKind;
   RawByteString FRememberedTunnelPassword;
+  bool FRememberedPasswordUsed;
   TTunnelThread * FTunnelThread;
   TSecureShell * FTunnel;
   TSessionData * FTunnelData;