# Set Password for user from Java SDK

**URL:** <https://devforum.okta.com/t/set-password-for-user-from-java-sdk/14350>\
**Category:** Questions\
**Created:** [May 21, 2021, 5:34pm UTC](https://devforum.okta.com/t/set-password-for-user-from-java-sdk/14350 "2021-05-21T17:34:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrAtAustin](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@jrAtAustin](https://devforum.okta.com/u/jrAtAustin)\
**Post date:** [May 21, 2021, 5:34pm UTC](https://devforum.okta.com/t/set-password-for-user-from-java-sdk/14350/1 "2021-05-21T17:34:42Z")

</div>

Can I set a user’s password at anytime as “admin/service” account? I am using the Java SDK and referencing [[Users | Okta Developer](https://developer.okta.com/docs/reference/api/users/#set-password)](Set Password)

Below is the Groovy code:

```
Client client = Clients.builder()
    .setOrgUrl("https://${domain}")
    .setClientCredentials(new TokenClientCredentials("${apiToken}"))
    .build()

UserList users = client.listUsers(user.getEmail(), null, null, null, null)
User user1 = users?.first()
String userId = user1?.getId()

Resource userPasswordRequest = client.instantiate(ExtensibleResource)
userPasswordRequest.put("credentials", client.instantiate(ExtensibleResource)
    .put("password", client.instantiate(ExtensibleResource)
    .put("value", password.toCharArray())))
Resource result = client.getDataStore().http()
    .setBody(userPasswordRequest)
    .post("/api/v1/users/"+ userId, User.class)
log.info("Result: ${result}")

```

I did not get any errors but the password is unchanged.

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [May 27, 2021, 6:47pm UTC](https://devforum.okta.com/t/set-password-for-user-from-java-sdk/14350/2 "2021-05-27T18:47:43Z")

</div>

Is there a reason you’re not using the UserCredentials [setPassword](https://developer.okta.com/okta-sdk-java/apidocs/com/okta/sdk/resource/user/UserCredentials.html#setPassword-com.okta.sdk.resource.user.PasswordCredential-) method to do this? This one should work for a super admin to be able to set the password for any user.

---

<div class="post-metadata">

**Author:** ![jrAtAustin](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@jrAtAustin](https://devforum.okta.com/u/jrAtAustin)\
**Post date:** [June 2, 2021, 3:34pm UTC](https://devforum.okta.com/t/set-password-for-user-from-java-sdk/14350/4 "2021-06-02T15:34:11Z")

</div>

@Andrea thanks for the suggestion, the code below worked when creating a User. I will try using UserCredentials.setPassword method.

```
        User user = UserBuilder.instance()
        .setEmail(email)
        .setLogin(username)
        .setFirstName(firstName)
        .setLastName(lastName)
        .setActive(active)
        .setBcryptPasswordHash(passwordHash, salt, rounds)
        .buildAndCreate(client)
```

---

<div class="post-metadata">

**Author:** ![vitalii.tytarenko](https://avatars.discourse-cdn.com/v4/letter/v/ccd318/32.png) [@vitalii.tytarenko](https://devforum.okta.com/u/vitalii.tytarenko)\
**Post date:** [September 29, 2021, 2:37pm UTC](https://devforum.okta.com/t/set-password-for-user-from-java-sdk/14350/5 "2021-09-29T14:37:21Z")

</div>

```
        PasswordCredential passwordCredential = client.instantiate(PasswordCredential.class)
            .setValue("NewPassword-!#123".toCharArray());
        user.getCredentials().setPassword(passwordCredential);
        user.update();
```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/oktadev/original/1X/589c4c5f80de422d01f47cee7185a7fb8227835c.png) [@system](https://devforum.okta.com/u/system)\
**Post date:** [October 11, 2021, 4:06pm UTC](https://devforum.okta.com/t/set-password-for-user-from-java-sdk/14350/6 "2021-10-11T16:06:54Z")

</div>

Closed on October 11, 2021, 4:06pm UTC

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
