The NetUserChangePassword function changes a user's password for a specified network server or domain.
NET_API_STATUS NET_API_FUNCTION NetUserChangePassword( IN LPCWSTR domainname OPTIONAL, IN LPCWSTR username OPTIONAL, IN LPCWSTR oldpassword, IN LPCWSTR newpassword );
A pointer to a constant string that specifies the user's old password.
A pointer to a constant string that specifies the user's new password.
If the function succeeds, the return value is NERR_Success.
If the function fails, the return value can be one of the following error codes.
||The user does not have access to the requested information.|
||The user has entered an invalid password.|
||The computer name is invalid.|
||The operation is allowed only on the primary domain controller of the domain.|
||The user name could not be found.|
||The password is shorter than required. (The password could also be too long, be too recent in its change history, not have enough unique characters, or not meet another password policy requirement.)|
If you are programming for Active Directory, you may be able to call certain Active Directory Service Interface (ADSI) methods to achieve the same result you can achieve by calling the network management user functions. For more information, see IADsUser and IADsComputer.
If an application calls the NetUserChangePassword function on a domain controller that is running Active Directory, access is allowed or denied based on the access control list (ACL) for the securable object. The default ACL permits only Domain Admins and Account Operators to call this function. On a member server or workstation, only Administrators and Power Users can call this function. A user can change his or her own password. For more information, see Security Requirements for the Network Management Functions. For more information on ACLs, ACEs, and access tokens, see Access Control Model.
The security descriptor of the User object is used to perform the access check for this function. In addition, the caller must have the "Change password" control access right on the User object. This right is granted to Anonymous Logon and Everyone by default.
Note that for the function to succeed, the oldpassword parameter must match the password as it currently exists.
In some cases, the process that calls the NetUserChangePassword function must also have the SE_CHANGE_NOTIFY_NAME privilege enabled; otherwise, NetUserChangePassword fails and GetLastError returns ERROR_ACCESS_DENIED. This privilege is not required for the LocalSystem account or for accounts that are members of the administrators group. By default, SE_CHANGE_NOTIFY_NAME is enabled for all users, but some administrators may disable the privilege for everyone. For more information about account privileges, see Privileges and Authorization Constants.
See Forcing a User to Change the Logon Password for a code sample that demonstrates how to force a user to change the logon password on the next logon using the NetUserGetInfo and NetUserSetInfo functions.
User account names are limited to 20 characters and group names are limited to 256 characters. In addition, account names cannot be terminated by a period and they cannot include commas or any of the following printable characters: ", /, , [, ], :, |, <, >, +, =, ;, ?, *. Names also cannot include characters in the range 1-31, which are nonprintable.
The NetUserChangePassword function does not control how the oldpassword and newpassword parameters are secured when sent over the network to a remote server. Any encryption of these parameters is handled by the Remote Procedure Call (RPC) mechanism supported by the network redirector that provides the network transport. Encryption is also controlled by the security mechanisms supported by the local computer and the security mechanisms supported by remote network server or domain specified in the domainname parameter. For more details on security when the Microsoft network redirector is used and the remote network server is running Microsoft Windows, see the protocol documentation for MS-RPCE, MS-SAMR, MS-SPNG, and MS-NLMP.
The following code sample demonstrates how to change a user's password with a call to the NetUserChangePassword function. All parameters to the function are required.
#ifndef UNICODE #define UNICODE #endif #pragma comment(lib, "netapi32.lib")
|Windows version||Windows 2000 Professional [desktop apps only] Windows 2000 Server [desktop apps only]|
|Header||lmaccess.h (include Lm.h)|