Skip to content

Commit 50d9b72

Browse files
committed
Added ChangeAccountPassword
1 parent eb1c4b7 commit 50d9b72

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

NtApiDotNet/Win32/Security/Authentication/AuthenticationPackage.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
using NtApiDotNet.Win32.Security.Authentication.Kerberos;
1818
using NtApiDotNet.Win32.Security.Authentication.Negotiate;
1919
using NtApiDotNet.Win32.Security.Authentication.Ntlm;
20+
using NtApiDotNet.Win32.Security.Buffers;
2021
using NtApiDotNet.Win32.Security.Native;
2122
using System;
2223
using System.Collections.Generic;
2324
using System.Linq;
24-
25+
2526
namespace NtApiDotNet.Win32.Security.Authentication
2627
{
2728
/// <summary>
@@ -338,6 +339,32 @@ public IServerAuthenticationContext CreateServer(AuthenticationCredentials crede
338339
}
339340
}
340341

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+
341368
/// <summary>
342369
/// Overridden ToString method.
343370
/// </summary>

NtApiDotNet/Win32/Security/Native/SecurityNativeMethods.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,19 @@ internal static extern SecStatusCode ImportSecurityContext(
204204
[Out] SecHandle phContext
205205
);
206206

207+
[DllImport("Secur32.dll", CharSet = CharSet.Unicode)]
208+
internal static extern SecStatusCode ChangeAccountPassword(
209+
string pszPackageName,
210+
string pszDomainName,
211+
string pszAccountName,
212+
string pszOldPassword,
213+
string pszNewPassword,
214+
[MarshalAs(UnmanagedType.U1)]
215+
bool bImpersonating,
216+
int dwReserved,
217+
SecBufferDesc pOutput
218+
);
219+
207220
[DllImport("sspicli.dll", CharSet = CharSet.Unicode)]
208221
internal static extern SecStatusCode SspiMarshalAuthIdentity(
209222
SafeBuffer AuthIdentity, // PSEC_WINNT_AUTH_IDENTITY_OPAQUE

0 commit comments

Comments
 (0)