# Manage console access

Reset an IAM user's console password, unlock it, turn its sign-in off or on, remove its second factors, or remove the password.

These apply to an IAM user that has a console password (see
[Give an IAM user console access](give-a-user-console-access.md)). Replace _alice_ with the user's
name.

## Prerequisites

- The IAM action in the table below, on the user.
- In the console, also `iam:GetUser` on the user to open its page (without it the page is not
  found) and `iam:GetLoginProfile` on the user: without it the **Console access** tab shows only
  that your policies do not grant it, and the **Danger zone** offers no console actions.
- In the console, also `iam:ListUsers` to open **Users** (without it the list says you do not have
  permission to list IAM users).

| Do                      | IAM action                | What happens                                                                                                                                          |
| ----------------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| Reset the password      | `iam:UpdateLoginProfile`  | The old password stops working, sessions and connected apps end, every lock is lifted. A new one is due at the next sign-in unless you say otherwise. |
| Unlock                  | `iam:UpdateLoginProfile`  | Lifts the lock on the user and on every locked address.                                                                                               |
| Turn off                | `iam:UpdateLoginProfile`  | No sign-in; sessions and connected apps end at once. The password is kept.                                                                            |
| Turn on                 | `iam:UpdateLoginProfile`  | Sign-in works again with the kept password.                                                                                                           |
| Remove second factors   | `iam:DeactivateMfaDevice` | Removes the authenticator app, recovery codes and passkeys; sessions and connected apps end.                                                          |
| Remove console password | `iam:DeleteLoginProfile`  | No more sign-in; sessions and connected apps end. Access keys are not affected.                                                                       |

## Reset, unlock, turn off or on

**Console**
1. Open **Identity**, choose **Users**, then choose alice, then **Console access**.
2. Choose what to do:
   - **Reset password**: choose **Generate one (shown once)** or **Type one**, keep or clear
     **Ask for a new password at the next sign-in**, then choose **Reset password**.
   - **Unlock**: shown only while the user or an address is locked.
   - **Turn off**, or **Turn on** when it is off.
3. The **Status** shows **On**, **Off** or **Locked**.

**CLI**
```sh
dcloud iam users update-login-profile user-id --generate-password
dcloud iam users update-login-profile user-id --unlock
dcloud iam users update-login-profile user-id --enabled=false
```

**API**
```http
PATCH /iam/api/users/user-id/login-profile
{ "generatePassword": true, "passwordResetRequired": true }
```

Send `{ "unlock": true }` to unlock, `{ "enabled": false }` or `{ "enabled": true }` to turn sign-in
off or on.

**Terraform**
On `dcloud_iam_user_login_profile`, a changed `password` resets it and `enabled = false` turns sign-in
off. Unlocking is not a Terraform setting.

## Remove second factors or the password

For a lost phone, remove the second factors: an IAM user has no mailbox to recover with. They sign
in with the password alone until they set up a new factor; if your organization requires
two-factor sign-in, they are asked to at once.

**Console**
1. Open the user, then choose **Danger zone**.
2. Choose **Remove second factors** and confirm, or choose **Remove console password**, type the
   user name and confirm. **Remove second factors** is offered only while the user has a second
   factor.

**CLI**
```sh
dcloud iam users deactivate-mfa user-id
dcloud iam users delete-login-profile user-id
```

**API**
```http
DELETE /iam/api/users/user-id/mfa
```

```http
DELETE /iam/api/users/user-id/login-profile
```

**Terraform**
Destroying the `dcloud_iam_user_login_profile` resource removes the console password. Second factors
are not a Terraform setting.

## How locks work

Wrong passwords in a row from one address, as many as the policy's **Lock after wrong passwords**
(5 by default), lock that address for **Lock for (minutes)** (15 by default). The user still signs
in from any other address, so someone who knows the user name cannot lock its owner out. Only 100
wrong passwords within 24 hours, from any addresses, lock the user everywhere. The **Locked** row
shows which applies.

The sign-in page gives the same answer for a wrong organization, user name or password, a locked
user and one that is turned off: `The organization, user name or password is not right. After several wrong attempts, sign-in pauses for a few minutes.`

## If it is refused

- 404 `This IAM user has no console password.`
- 409 `This IAM user is suspended (for example a former member) and cannot be given console access. Invite the person again, or create a new IAM user.`
  when turning on a former member's sign-in.
- 409 `Your organization has turned off console passwords for IAM users. Ask your administrator how to sign in.`
  or `Your organization signs in with single sign-on, so IAM-user console passwords are off. Ask your administrator.`
  when turning sign-in on while console passwords are off or single sign-on is enforced.
- 400 `The password does not meet the organization's policy: …`

## Related

- [Give an IAM user console access](give-a-user-console-access.md) · [Set the password policy](set-the-password-policy.md)
- `iam.users.update-login-profile` · `dcloud iam users update-login-profile` · `dcloud_iam_user_login_profile`
