diff --git a/web/pgadmin/utils/driver/psycopg3/connection.py b/web/pgadmin/utils/driver/psycopg3/connection.py index ad544e99b25..57b9239dbaa 100644 --- a/web/pgadmin/utils/driver/psycopg3/connection.py +++ b/web/pgadmin/utils/driver/psycopg3/connection.py @@ -258,12 +258,20 @@ def _decode_password(self, encpass, manager, password, crypt_key): if isinstance(password, bytes): password = password.decode() except Exception as e: - manager.stop_ssh_tunnel() - current_app.logger.exception(e) - return True, \ - _( - "Failed to decrypt the saved password.\nError: {0}" - ).format(str(e)), password + # The saved password could not be decrypted. This happens + # when the stored ciphertext was encrypted with a different + # key (e.g. OIDC/OAuth2 logins where the derived encryption + # key changed between sessions), leaving un-decodable bytes + # (typically a "'utf-8' codec can't decode byte 0x.." error). + # Instead of failing every connection attempt permanently, + # discard the bad saved password and continue so the user is + # prompted for the password again. + current_app.logger.warning( + 'Ignoring the saved password as it could not be ' + 'decrypted. The user will be prompted for the password. ' + 'Error: {0}'.format(str(e)) + ) + return False, '', None return False, '', password def connect(self, **kwargs):