# Change your password

`POST https://api.mailmasker.org/api/v1/auth/password`

Set a new password, given your current one.

- Who can use it: Any signed-in account
- Area: Sign-in and tokens
- Answers 200 OK when it works
- Page: https://developer.mailmasker.org/change-password

Works whether or not you have a recovery address. The tokens of your other sessions stop working at once, while the session making this call stays signed in. Mail apps that sign in with your password, such as a phone's, need the new one too.

## Parameters

| Name | In | Required | What it is | Example |
|---|---|---|---|---|
| `current_password` | body | yes | Your password now. | `$PASSWORD` |
| `new_password` | body | yes | The new password, at least 8 characters. | `$NEW_PASSWORD` |

## Good to know

- A wrong current password answers 403, and a new one shorter than 8 characters answers 400.
- If someone else may be signed in as you, sign out your other sessions first, then change your password.

## Examples

cURL:

```bash
curl -s -X POST 'https://api.mailmasker.org/api/v1/auth/password' \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' \
  -d "{\"current_password\":\"$PASSWORD\",\"new_password\":\"$NEW_PASSWORD\"}"
```

Perl:

```perl
use Mojo::Base -strict;
use Mojo::UserAgent;

my $ua  = Mojo::UserAgent->new;
my $res = $ua->post('https://api.mailmasker.org/api/v1/auth/password',
    { Authorization => "Bearer $ENV{TOKEN}" },
    json => { current_password => $ENV{PASSWORD}, new_password => $ENV{NEW_PASSWORD} })->result;
die $res->code, ' ', ($res->json('/error') // $res->message), "\n" unless $res->is_success;
print $res->body, "\n";
```

homelab-cli:

There is no homelab-cli command for this yet.

## Response

200 OK:

```json
{ "ok": true }
```
