# Set the password policy

Set the rules for IAM users' console passwords, lockouts and sign-in length, or turn IAM-user password sign-in off.

The policy applies to IAM users with a console password only, not to people's own email accounts.

| Setting                         | Default | Range                           |
| ------------------------------- | ------- | ------------------------------- |
| Minimum length                  | 12      | 8–128                           |
| Uppercase, lowercase, number    | on      |                                 |
| Symbol                          | off     |                                 |
| Password expires after (days)   | never   | 1–365                           |
| Lock after wrong passwords      | 5       | 3–20, in a row from one address |
| Lock for (minutes)              | 15      | 1–1440                          |
| Longest sign-in (hours)         | 12      | 1–168                           |
| Console passwords for IAM users | on      |                                 |

## Prerequisites

- Permission for `iam:UpdatePasswordPolicy`; to return to the defaults, `iam:DeletePasswordPolicy`.
- In the console, also `iam:GetPasswordPolicy`: without it Organization settings show no
  **IAM-user sign-in** section. **Restore defaults** there also needs `iam:UpdatePasswordPolicy`.

## Change the policy

**Console**
1. Open [Organization settings](/settings).
2. Under **IAM-user sign-in**, change the fields: **Minimum length**,
   **Lock after wrong passwords**, **Lock for (minutes)**, **Longest sign-in (hours)**,
   **Password expires after (days)** (empty for never), and under **Every password contains**,
   select or clear **An uppercase letter**, **A lowercase letter**, **A number** and **A symbol**.
3. (Optional) Turn off **Console passwords for IAM users**.
4. Choose **Save sign-in rules**.

To go back to the defaults, choose **Restore defaults**.

**CLI**
The update sets the whole policy, so every flag is required.

```sh
dcloud iam password-policy update --min-length 14 --require-uppercase --require-lowercase \
  --require-numbers --require-symbols=false --max-age-days 180 --lockout-threshold 5 \
  --lockout-minutes 30 --max-session-hours 8 --console-passwords-allowed
```

`dcloud iam password-policy delete` returns to the defaults.

**API**
```http
PUT /iam/api/password-policy
{ "minLength": 14, "requireUppercase": true, "requireLowercase": true, "requireNumbers": true, "requireSymbols": false, "maxAgeDays": null, "lockoutThreshold": 5, "lockoutMinutes": 30, "maxSessionHours": 8, "consolePasswordsAllowed": true }
```

`DELETE /iam/api/password-policy` returns to the defaults.

**Terraform**
```hcl
resource "dcloud_iam_password_policy" "this" {
  min_length        = 14
  max_age_days      = 180
  lockout_minutes   = 30
  max_session_hours = 8
}
```

There is one policy per organization: destroying the resource restores the defaults.

## Result

New passwords follow the policy; an existing password is checked at its next change. A password
older than **Password expires after (days)** must be changed at the next sign-in. An IAM user's
console session ends after **Longest sign-in (hours)** even while in use.

Turning **Console passwords for IAM users** off signs every IAM user out and keeps their passwords;
no IAM user signs in with a password until it is on again. An enforced single sign-on connection
has the same effect (see [Enforce single sign-on](enforce-single-sign-on.md)). The sign-in page
tells a user this only after a correct password.

The settings also show the **Sign-in link** IAM users sign in at.

## If it is refused

Values outside the ranges above are refused with 400.

## Related

- [Give an IAM user console access](give-a-user-console-access.md) · [Manage console access](manage-console-access.md)
- `iam.password-policy.update` · `dcloud iam password-policy update` · `dcloud_iam_password_policy`
