@@ -122,6 +122,52 @@ public static void SqlConnectionChangePasswordSecureString()
122122 }
123123 }
124124
125+ [ CheckConnStrSetupFact ]
126+ public static void OldCredentialsShouldFail ( )
127+ {
128+ String user = "u" + Guid . NewGuid ( ) . ToString ( ) . Replace ( "-" , "" ) ;
129+ String passStr = "Pax561O$T5K#jD" ;
130+
131+ try
132+ {
133+ createTestUser ( user , passStr ) ;
134+
135+ SqlConnectionStringBuilder sqlConnectionStringBuilder = new SqlConnectionStringBuilder ( DataTestUtility . TcpConnStr ) ;
136+ sqlConnectionStringBuilder . Remove ( "User ID" ) ;
137+ sqlConnectionStringBuilder . Remove ( "Password" ) ;
138+ sqlConnectionStringBuilder . IntegratedSecurity = false ;
139+
140+ SecureString password = new SecureString ( ) ;
141+ passStr . ToCharArray ( ) . ToList ( ) . ForEach ( x => password . AppendChar ( x ) ) ;
142+ password . MakeReadOnly ( ) ;
143+ SqlCredential credential = new SqlCredential ( user , password ) ;
144+
145+ using ( SqlConnection conn1 = new SqlConnection ( sqlConnectionStringBuilder . ConnectionString , credential ) )
146+ using ( SqlConnection conn2 = new SqlConnection ( sqlConnectionStringBuilder . ConnectionString , credential ) )
147+ using ( SqlConnection conn3 = new SqlConnection ( sqlConnectionStringBuilder . ConnectionString , credential ) )
148+ using ( SqlConnection conn4 = new SqlConnection ( sqlConnectionStringBuilder . ConnectionString , credential ) )
149+ {
150+ conn1 . Open ( ) ;
151+ conn2 . Open ( ) ;
152+ conn3 . Open ( ) ;
153+ conn4 . Open ( ) ;
154+
155+ SecureString newPassword = new SecureString ( ) ;
156+ "NewPassword" . ToCharArray ( ) . ToList ( ) . ForEach ( x => newPassword . AppendChar ( x ) ) ;
157+ newPassword . MakeReadOnly ( ) ;
158+ SqlConnection . ChangePassword ( sqlConnectionStringBuilder . ConnectionString , credential , newPassword ) ;
159+ using ( SqlConnection conn5 = new SqlConnection ( sqlConnectionStringBuilder . ConnectionString , new SqlCredential ( user , password ) ) )
160+ {
161+ Assert . Throws < SqlException > ( ( ) => conn5 . Open ( ) ) ;
162+ }
163+ }
164+ }
165+ finally
166+ {
167+ dropTestUser ( user ) ;
168+ }
169+ }
170+
125171 private static void createTestUser ( string username , string password )
126172 {
127173 // Creates a test user with read permissions.
0 commit comments