|
17 | 17 | using NtApiDotNet.Win32.Security.Authentication.Kerberos; |
18 | 18 | using NtApiDotNet.Win32.Security.Authentication.Negotiate; |
19 | 19 | using NtApiDotNet.Win32.Security.Authentication.Ntlm; |
| 20 | +using NtApiDotNet.Win32.Security.Buffers; |
20 | 21 | using NtApiDotNet.Win32.Security.Native; |
21 | 22 | using System; |
22 | 23 | using System.Collections.Generic; |
23 | 24 | using System.Linq; |
24 | | - |
| 25 | + |
25 | 26 | namespace NtApiDotNet.Win32.Security.Authentication |
26 | 27 | { |
27 | 28 | /// <summary> |
@@ -338,6 +339,32 @@ public IServerAuthenticationContext CreateServer(AuthenticationCredentials crede |
338 | 339 | } |
339 | 340 | } |
340 | 341 |
|
| 342 | + /// <summary> |
| 343 | + /// Change an account password using this package. |
| 344 | + /// </summary> |
| 345 | + /// <param name="domain">The user's domain name.</param> |
| 346 | + /// <param name="username">The user's name.</param> |
| 347 | + /// <param name="old_password">The user's old password.</param> |
| 348 | + /// <param name="new_password">The user's new password.</param> |
| 349 | + /// <param name="impersonating">Whether the caller is impersonating.</param> |
| 350 | + public void ChangeAccountPassword(string domain, string username, |
| 351 | + string old_password, string new_password, bool impersonating = false) |
| 352 | + { |
| 353 | + var password_info_buffer = new SecurityBufferAllocMem(SecurityBufferType.ChangePassResponse); |
| 354 | + List<SecurityBuffer> buffers = new List<SecurityBuffer> |
| 355 | + { |
| 356 | + password_info_buffer |
| 357 | + }; |
| 358 | + using (var list = new DisposableList()) |
| 359 | + { |
| 360 | + var output = buffers.ToBufferList(list); |
| 361 | + var desc = output.ToDesc(list); |
| 362 | + SecurityNativeMethods.ChangeAccountPassword(Name, domain, username, |
| 363 | + old_password, new_password, impersonating, 0, desc).CheckResult(); |
| 364 | + buffers.UpdateBuffers(desc); |
| 365 | + } |
| 366 | + } |
| 367 | + |
341 | 368 | /// <summary> |
342 | 369 | /// Overridden ToString method. |
343 | 370 | /// </summary> |
|
0 commit comments