# X-Pack create user using Java API, wrong password

**URL:** <https://discuss.elastic.co/t/x-pack-create-user-using-java-api-wrong-password/77824>\
**Category:** Elasticsearch\
**Created:** [March 8, 2017, 1:33pm UTC](https://discuss.elastic.co/t/x-pack-create-user-using-java-api-wrong-password/77824 "2017-03-08T13:33:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bogdan.R](https://avatars.discourse-cdn.com/v4/letter/b/aeb1de/32.png) [@Bogdan.R](https://discuss.elastic.co/u/Bogdan.R)\
**Post date:** [March 8, 2017, 1:33pm UTC](https://discuss.elastic.co/t/x-pack-create-user-using-java-api-wrong-password/77824/1 "2017-03-08T13:33:38Z")

</div>

Hi,  
I'm trying to create a new user using X-Pack Java API:

```
    final PutUserRequest putUserRequest = new PutUserRequest();
    putUserRequest .enabled(true);
    putUserRequest .username("userName");
    putUserRequest .fullName("userFullName");
    putUserRequest .passwordHash("password".hashCode());
    putUserRequest .email("a@b.com");
    putUserRequest .roles("kibana_user");

    final XPackClient xPackClient = new XPackClient(transportClient);
    xPackClient.security().putUser(putUser, null);

```

The user is created but when I try to log in I'm getting wrong password message. I've tried multiple ways to calculate the password hash, and sizes, but still not working.

How should the passwordHash be generated?

Regards,

---

<div class="post-metadata">

**Author:** ![TimV](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timv/32/13162_2.png) [@TimV](https://discuss.elastic.co/u/TimV)\
**Post date:** [March 17, 2017, 1:19am UTC](https://discuss.elastic.co/t/x-pack-create-user-using-java-api-wrong-password/77824/2 "2017-03-17T01:19:07Z")

</div>

> [@Bogdan.R](#):
>
> How should the passwordHash be generated?

You should use `org.elasticsearch.xpack.security.authc.support.Hasher.BCRYPT`.

---

<div class="post-metadata">

**Author:** ![Bogdan.R](https://avatars.discourse-cdn.com/v4/letter/b/aeb1de/32.png) [@Bogdan.R](https://discuss.elastic.co/u/Bogdan.R)\
**Post date:** [March 27, 2017, 5:42am UTC](https://discuss.elastic.co/t/x-pack-create-user-using-java-api-wrong-password/77824/3 "2017-03-27T05:42:41Z")

</div>

Hi Tim, thank you for the reply. We actually managed to make it work using PutUserRequestBuilder.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 24, 2017, 5:42am UTC](https://discuss.elastic.co/t/x-pack-create-user-using-java-api-wrong-password/77824/4 "2017-04-24T05:42:53Z")

</div>

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