@@ -81,7 +81,7 @@ export class ConnectionDialogWebviewController extends ReactWebviewPanelControll
81
81
82
82
private async loadRecentConnections ( ) {
83
83
const recentConnections = this . _mainController . connectionManager . connectionStore . loadAllConnections ( true ) . map ( c => c . connectionCreds ) ;
84
- const dialogConnections = [ ] ;
84
+ const dialogConnections : IConnectionDialogProfile [ ] = [ ] ;
85
85
for ( let i = 0 ; i < recentConnections . length ; i ++ ) {
86
86
dialogConnections . push ( await this . initializeConnectionForDialog ( recentConnections [ i ] ) ) ;
87
87
}
@@ -105,28 +105,41 @@ export class ConnectionDialogWebviewController extends ReactWebviewPanelControll
105
105
this . state . connectionProfile = emptyConnection ;
106
106
}
107
107
108
- private async initializeConnectionForDialog ( connection : IConnectionInfo ) {
108
+ private async initializeConnectionForDialog ( connection : IConnectionInfo ) : Promise < IConnectionDialogProfile > {
109
109
// Load the password if it's saved
110
110
const isConnectionStringConnection = connection . connectionString !== undefined && connection . connectionString !== '' ;
111
- const password = await this . _mainController . connectionManager . connectionStore . lookupPassword ( connection , isConnectionStringConnection ) ;
112
111
if ( ! isConnectionStringConnection ) {
112
+ const password = await this . _mainController . connectionManager . connectionStore . lookupPassword ( connection , isConnectionStringConnection ) ;
113
113
connection . password = password ;
114
114
} else {
115
- connection . connectionString = '' ;
116
- // extract password from connection string it starts after 'Password=' and ends before ';'
117
- const passwordIndex = password . indexOf ( 'Password=' ) === - 1 ? password . indexOf ( 'password=' ) : password . indexOf ( 'Password=' ) ;
118
- if ( passwordIndex !== - 1 ) {
119
- const passwordStart = passwordIndex + 'Password=' . length ;
120
- const passwordEnd = password . indexOf ( ';' , passwordStart ) ;
121
- if ( passwordEnd !== - 1 ) {
122
- connection . password = password . substring ( passwordStart , passwordEnd ) ;
115
+ // If the connection is a connection string connection with SQL Auth:
116
+ // * the full connection string is stored as the "password" in the credential store
117
+ // * we need to extract the password from the connection string
118
+ // If the connection is a connection string connection with a different auth type, then there's nothing in the credential store.
119
+
120
+ const connectionString = await this . _mainController . connectionManager . connectionStore . lookupPassword ( connection , isConnectionStringConnection ) ;
121
+
122
+ if ( connectionString ) {
123
+ const passwordIndex = connectionString . toLowerCase ( ) . indexOf ( 'password=' ) ;
124
+
125
+ if ( passwordIndex !== - 1 ) {
126
+ // extract password from connection string; found between 'Password=' and the next ';'
127
+ const passwordStart = passwordIndex + 'password=' . length ;
128
+ const passwordEnd = connectionString . indexOf ( ';' , passwordStart ) ;
129
+ if ( passwordEnd !== - 1 ) {
130
+ connection . password = connectionString . substring ( passwordStart , passwordEnd ) ;
131
+ }
132
+
133
+ // clear the connection string from the IConnectionDialogProfile so that the ugly connection string key
134
+ // that's used to look up the actual connection string (with password) isn't displayed
135
+ connection . connectionString = '' ;
123
136
}
124
137
}
125
-
126
138
}
139
+
127
140
const dialogConnection = connection as IConnectionDialogProfile ;
128
- // Set the profile name
129
- dialogConnection . profileName = dialogConnection . profileName ?? getConnectionDisplayName ( connection ) ;
141
+ // Set the display name
142
+ dialogConnection . displayName = dialogConnection . profileName ? dialogConnection . profileName : getConnectionDisplayName ( connection ) ;
130
143
return dialogConnection ;
131
144
}
132
145
0 commit comments