# `setPassword()`

Sets the specified user's password to the specified value.

## Syntax

```java
SetPasswordResult setPasswordResult = connection.setPassword(ID userID, string password);
```

## Usage

Use [`setPassword()`](/docs/platform/api/guide/sforce-api-calls-setpassword.md) to change the password of a [User](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_user.htm) or [SelfServiceUser](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_selfserviceuser.htm) to a value that you specify. For example, a client application prompts a user to specify a different password, and then invokes `setPassword()` for an admin to change the user's password. Use [`resetPassword()`](/docs/platform/api/guide/sforce-api-calls-resetpassword.md) instead if you want to reset the password with a random value generated by the API.

This call can be used to allow users to change their own passwords, as long as their org’s Password Policies setting **Allow use of setPassword() API for self-resets** is enabled. Otherwise, use [`changeOwnPassword()`](/docs/platform/api/guide/sforce-api-calls-changeownpassword.md), which is more secure because it verifies the user’s current password before allowing the change.

Your client application must be logged in with sufficient access rights to change the password for the specified user. For more information, see [Factors that Affect Data Access](/docs/platform/api/guide/calls.md).

For information on IDs, see [ID Field Type](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/field_types.htm#i1435616).

This call can use the session ID returned in [LoginResult](/docs/platform/api/guide/sforce-api-calls-login-loginresult.md) if the password has expired. For more information, see [`passwordExpired`](/docs/platform/api/guide/sforce-api-calls-login-loginresult.md).

## Sample Code—Java

This sample accepts user ID and password parameters, which it uses in the `setPassword()` call to set the password of the specified user.

```codesegment
public void doSetPassword(String userId, String newPasswd) {
   try {
      SetPasswordResult result = connection.setPassword(userId, newPasswd);
      System.out.println("The password for user ID " + userId + " changed to "
            + newPasswd);
   } catch (ConnectionException ce) {
      ce.printStackTrace();
   }
}
```

## Sample Code—C\#

This sample accepts user ID and password parameters, which it uses in the `setPassword()` call to set the password of the specified user.

```codesegment
public void doSetPassword(String userId, String newPasswd)
{
   try
   {
      SetPasswordResult result = binding.setPassword(userId, newPasswd);
      Console.WriteLine("The password for user ID " + userId + " changed to "
            + newPasswd);
   }
   catch (SoapException e)
   {
      Console.WriteLine("An unexpected error has occurred: " +
                        e.Message + "\n" + e.StackTrace);
   }
}
```

## Arguments

| Name       | Type   | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ---------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `userID`   | ID     | ID of the [User](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_user.htm) or [SelfServiceUser](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_selfserviceuser.htm) whose password you want to reset. For information on IDs, see [ID Field Type](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/field_types.htm#i1435616). |
| `password` | string | New password to use for the specified user.                                                                                                                                                                                                                                                                                                                                                                                                                                                    |

## Response

SetPasswordResult (empty)

## Fault

[`InvalidIdFault`](/docs/platform/api/guide/sforce-api-calls-concepts-core-data-objects.md)

[`UnexpectedErrorFault`](/docs/platform/api/guide/sforce-api-calls-concepts-core-data-objects.md)

**See Also**

- [resetPassword()](/docs/platform/api/guide/sforce-api-calls-resetpassword.md)
- [Utility Calls](/docs/platform/api/guide/utility-calls.md)
- [changeOwnPassword()](/docs/platform/api/guide/sforce-api-calls-changeownpassword.md)
