[CodeBlog] PInvoke code to change users windows password - by simon at Sat, 16 May 2009 21:32:20 GMT
Very quick snippet that I just made use of to allow users to remotely change passwords over the web. Just leave the domainname and username black to change the current users password. This works great from ASP.NET and requires no special permissions, unlike some solutions that use LDAP or impersonation.
[DllImport("netapi32.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
static extern uint NetUserChangePassword(string domainname, string username, string oldpassword, string newpassword);