> For the complete documentation index, see [llms.txt](https://spice.docs.medtroniclabs.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://spice.docs.medtroniclabs.org/admin-guide/account-lock-and-unlock.md).

# Account Lock & Unlock

SPICE protects user accounts by locking them after repeated failed sign-in attempts. Administrators can see who is locked and unlock them. This page explains why accounts lock, how to unlock a user, and how to list and reactivate deactivated records.

## Why an account locks

An account locks when a user enters the wrong password too many times in a row.

| Setting                 | Default   | Meaning                                                                                      |
| ----------------------- | --------- | -------------------------------------------------------------------------------------------- |
| Failed attempts allowed | 5         | The account locks on the 5th consecutive wrong password.                                     |
| Lock window             | 5 minutes | While the account is locked, sign-in is refused for this long after the last failed attempt. |

Both values can be changed for your deployment, so ask your system administrator if your organisation uses different settings.

How it behaves:

* A successful sign-in resets the count of failed attempts to zero.
* While the account is locked, even the correct password is refused. The user sees a **Login failed** message.
* After the lock window passes, the user can try again. The failed-attempt count starts again from the new attempt.
* Setting a new password (through a reset link, by an administrator, or from **Change Password**) clears the lock and the failed-attempt count straight away.
* Unlocking the user as an administrator also clears the lock immediately, as described below.

Separately, a user who requests too many password reset emails (5 in an hour by default) is told **Password reset attempt exceeded. Please try after sometime.** Unlocking the user also clears this counter.

## Who can unlock users

Super administrators, region administrators, district administrators, sub-district administrators and facility administrators can unlock users. Each administrator sees only the users in their own area:

* Super administrators see all locked users.
* Region, district and sub-district administrators see locked users in their part of the hierarchy.
* Facility administrators see locked users of their own facilities.

## View locked users

1. Select your name at the top right to open the user menu.
2. Select **Locked Users**.
3. The page lists each locked user with their **Name** and **Email ID** (the username they sign in with).
4. Use the search box (**Search Email**) to find a user by username.

The list is empty when nobody in your area is locked.

## Unlock a user

1. Open **Locked Users** and find the user.
2. Select the **Unlock User** icon on the row.
3. The portal shows **User unlocked successfully.** and the user disappears from the list.
4. Tell the user they can sign in again with their existing password. If they have forgotten it, ask them to use **Forgot password?** on the sign-in page, or reset it for them as described in [Users, Roles & Access](https://spice.docs.medtroniclabs.org/admin-guide/users-roles-and-access.md#reset-a-password).

Unlocking a user:

* clears the lock and the count of failed sign-in attempts,
* clears the password reset email counter, and
* makes sure the account is marked as active.

If unlocking fails you see **Unable to unlock the user. Please try after sometime.** Refresh the page and try again. If the list itself does not load you see **Unable to load the locked users list. Please try after sometime.**

## If a user still cannot sign in

Work through this list:

| Check                              | What to do                                                                                                                                                                  |
| ---------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| The user is locked                 | Unlock them as above.                                                                                                                                                       |
| The password is wrong or forgotten | Reset the password. See [Users, Roles & Access](https://spice.docs.medtroniclabs.org/admin-guide/users-roles-and-access.md#reset-a-password).                               |
| The reset link has expired         | Send a new link. Links last 60 minutes by default.                                                                                                                          |
| The user has been deactivated      | Reactivate the user from the users list with the **Active** toggle.                                                                                                         |
| The facility has been deactivated  | Reactivate the facility. Users cannot be reactivated while their facility is deactivated. See [Facilities](https://spice.docs.medtroniclabs.org/admin-guide/facilities.md). |
| The district has been deactivated  | Reactivate the district from **Deactivated Records**. See below.                                                                                                            |

## Deactivated records

Deactivating a district hides it and everything beneath it. The **Deactivated Records** page lists deactivated districts so that you can reactivate them. Super administrators and region administrators can use it; region administrators see only the districts of their own region.

### View deactivated districts

1. Open the user menu and select **Deactivated Records**.
2. The page is titled with the name of your district level, for example **Deactivated Districts**, and lists:
   * **Name**
   * **Deactivated Date**
   * **Deactivated Reason**, one of **Unable to pay**, **Contract expired**, **Site closure**, **Inactive site** or **Other**
3. Use the search box to find a district by name.

### Reactivate a district

1. Select the activate icon on the district's row.
2. Confirm the message **Are you sure want to activate the District?**
3. The portal shows **District activated successfully.** and the district leaves the list.

Reactivating a district reactivates the sub-districts, facilities and users that were deactivated together with it.

### Deactivated facilities and users

Facilities and users are not listed on this page. Reactivate them from their own lists:

* **Facilities:** switch the **Active** toggle on the dimmed facility row. See [Facilities](https://spice.docs.medtroniclabs.org/admin-guide/facilities.md).
* **Users:** switch the **Active** toggle on the user's row. See [Users, Roles & Access](https://spice.docs.medtroniclabs.org/admin-guide/users-roles-and-access.md).

## Tips

* Encourage users to use **Forgot password?** rather than repeatedly guessing, because guessing locks the account.
* Unlock users only after you are confident the request comes from the account owner.
* Review **Locked Users** regularly. A growing list may indicate a sign-in problem, such as a mistyped shared password.
