Browse Source

Bug fix: Renaming tab invalidated remembered password

Source commit: 7d667513de9d9748b13ad183342d1a0bc85d7e9b
Martin Prikryl 2 years ago
parent
commit
5bcf370af8
3 changed files with 14 additions and 8 deletions
  1. 11 6
      source/core/SessionData.cpp
  2. 1 0
      source/core/SessionData.h
  3. 2 2
      source/core/Terminal.cpp

+ 11 - 6
source/core/SessionData.cpp

@@ -2707,6 +2707,11 @@ UnicodeString __fastcall TSessionData::DecryptPassword(const RawByteString & Pas
   return Result;
 }
 //---------------------------------------------------------------------
+UnicodeString TSessionData::GetSessionPasswordEncryptionKey() const
+{
+  return UserName + HostName;
+}
+//---------------------------------------------------------------------
 bool __fastcall TSessionData::GetCanLogin()
 {
   return !FHostName.IsEmpty();
@@ -2890,24 +2895,24 @@ UnicodeString TSessionData::GetUserNameSource()
 //---------------------------------------------------------------------
 void __fastcall TSessionData::SetPassword(UnicodeString avalue)
 {
-  RawByteString value = EncryptPassword(avalue, UserName+HostName);
+  RawByteString value = EncryptPassword(avalue, GetSessionPasswordEncryptionKey());
   SET_SESSION_PROPERTY(Password);
 }
 //---------------------------------------------------------------------
 UnicodeString __fastcall TSessionData::GetPassword() const
 {
-  return DecryptPassword(FPassword, UserName+HostName);
+  return DecryptPassword(FPassword, GetSessionPasswordEncryptionKey());
 }
 //---------------------------------------------------------------------
 void __fastcall TSessionData::SetNewPassword(UnicodeString avalue)
 {
-  RawByteString value = EncryptPassword(avalue, UserName+HostName);
+  RawByteString value = EncryptPassword(avalue, GetSessionPasswordEncryptionKey());
   SET_SESSION_PROPERTY(NewPassword);
 }
 //---------------------------------------------------------------------
 UnicodeString __fastcall TSessionData::GetNewPassword() const
 {
-  return DecryptPassword(FNewPassword, UserName+HostName);
+  return DecryptPassword(FNewPassword, GetSessionPasswordEncryptionKey());
 }
 //---------------------------------------------------------------------
 void __fastcall TSessionData::SetChangePassword(bool value)
@@ -4581,12 +4586,12 @@ void __fastcall TSessionData::SetWinTitle(UnicodeString value)
 //---------------------------------------------------------------------
 UnicodeString __fastcall TSessionData::GetEncryptKey() const
 {
-  return DecryptPassword(FEncryptKey, UserName+HostName);
+  return DecryptPassword(FEncryptKey, GetSessionPasswordEncryptionKey());
 }
 //---------------------------------------------------------------------
 void __fastcall TSessionData::SetEncryptKey(UnicodeString avalue)
 {
-  RawByteString value = EncryptPassword(avalue, UserName+HostName);
+  RawByteString value = EncryptPassword(avalue, GetSessionPasswordEncryptionKey());
   SET_SESSION_PROPERTY(EncryptKey);
 }
 //---------------------------------------------------------------------

+ 1 - 0
source/core/SessionData.h

@@ -535,6 +535,7 @@ public:
   bool HasAutoCredentials();
   int GetDefaultPort();
   UnicodeString ResolvePublicKeyFile();
+  UnicodeString GetSessionPasswordEncryptionKey() const;
 
   UnicodeString __fastcall GenerateOpenCommandArgs(bool Rtf);
   void __fastcall GenerateAssemblyCode(TAssemblyLanguage Language, UnicodeString & Head, UnicodeString & Tail, int & Indent);

+ 2 - 2
source/core/Terminal.cpp

@@ -1344,7 +1344,7 @@ void __fastcall TTerminal::Idle()
 //---------------------------------------------------------------------
 RawByteString __fastcall TTerminal::EncryptPassword(const UnicodeString & Password)
 {
-  return Configuration->EncryptPassword(Password, SessionData->SessionName);
+  return Configuration->EncryptPassword(Password, SessionData->GetSessionPasswordEncryptionKey());
 }
 //---------------------------------------------------------------------
 UnicodeString __fastcall TTerminal::DecryptPassword(const RawByteString & Password)
@@ -1352,7 +1352,7 @@ UnicodeString __fastcall TTerminal::DecryptPassword(const RawByteString & Passwo
   UnicodeString Result;
   try
   {
-    Result = Configuration->DecryptPassword(Password, SessionData->SessionName);
+    Result = Configuration->DecryptPassword(Password, SessionData->GetSessionPasswordEncryptionKey());
   }
   catch(EAbort &)
   {