---
type: api
title: Change passwords
description: **All methods and paths for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-security-change-password
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-security-change-password
products:
  - Elasticsearch
---

# Change passwords


Availability:

## Paths

- `POST` (also `PUT`) `/_security/user/{username}/_password`
- `POST` (also `PUT`) `/_security/user/_password`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#basicauth)
- [Bearer auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#bearerauth)

#### Path Parameters

- `username` (string) — optional, leave it out to use `/_security/user/_password`
  The user whose password you want to change. If you do not specify this
parameter, the password is changed for the current user.

## Description

Change the passwords of users in the native realm and built-in users.

## Query String Parameters

- `refresh` (enum Refresh)
  If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes.
  Values: `true`, `false`, `wait_for`

## Request Body

`application/json`

- `password` (string) — optional
  The new password value. Passwords must be at least 6 characters long.
- `password_hash` (string) — optional
  A hash of the new password value. This must be produced using the same
hashing algorithm as has been configured for password storage. For more details,
see the explanation of the `xpack.security.authc.password_hashing.algorithm`
setting.

## Response

`application/json`

Type: `object`

## Code Examples

#### Console

```console
POST /_security/user/jacknich/_password
{
  "password" : "new-test-password"
}
```

#### JavaScript

```javascript
const response = await client.security.changePassword({
  username: "jacknich",
  password: "new-test-password",
});
```

#### Python

```python
resp = client.security.change_password(
    username="jacknich",
    password="new-test-password",
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/_security/user/jacknich/_password" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "password": "new-test-password"
  }'
```

#### Java

```java
client.security().changePassword(c -> c
    .password("new-test-password")
    .username("jacknich")
);
```

#### C#

```c#
var response = await client.Security
    .ChangePasswordAsync(d1 => d1
        .Username("jacknich")
        .Password("new-test-password")
    );
```

#### PHP

```php
$resp = $client->security()->changePassword([
    "username" => "jacknich",
    "body" => [
        "password" => "new-test-password",
    ],
]);
```

#### Ruby

```ruby
response = client.security.change_password(
  username: "jacknich",
  body: {
    "password": "new-test-password"
  }
)
```

