# Passwords and password rules

This page brings together everything about passwords: what a good one must look like, when it must be changed, how users change and recover it, and how the server keeps it.

## What a password must look like

Rules are set in two places.

| Where | Holds for | Page |
|---|---|---|
| the **Admin** tab of a user, usually of `default` or a template | that user and everybody who inherits from it | [Admin](Users-Admin.md#password-rules) |
| **Password Rules** in the Encryption section of the Preferences | the server | [How passwords are stored](Prefs-Encryption-Passwords.md#password-rules) |

The rules: a minimum length; minimum numbers of digits, lower case letters, capital letters and special characters; characters that are not allowed; and how many earlier passwords are remembered and refused.

A rule is checked when a password is **set**: by the user, by an administrator in the User Manager, by an import, by self registration. Passwords that exist are not checked again; to bring everybody under a new rule, make their passwords expire.

For length and strength, follow current guidance: long beats complicated. A minimum of 12 to 14 characters and a history of a handful does more than a demand for three kinds of special characters.

## When a password must be changed

| Setting | Where |
|---|---|
| **Expire Password**, after so many days | [Password and account expiry](Users-Restrictions-Password-Expiry.md) |
| **Expire now**, for one user at once | the same |
| a notice some days before, by a job | the same |
| **Minimum age for password**, so that a user cannot run through the history in a minute | the same |
| change at the next login, for a password an administrator set | **Setup** tab of the user: [Setup](Users-Setup.md) |

Take accounts of scripts out of expiry; give them keys or tokens instead.

## Changing and recovering

| A user | Needs |
|---|---|
| changes their own password, in the web interface under **User Options**, or with the `SITE PASS` command | **SITE PASS** in [Site preferences](Users-Admin-Site-Preferences.md): on for a new user |
| asks for a reset by mail from the login page | **Allow password to be emailed if they forget it**, a mail address on the account, and a working [mail server](Prefs-General-SMTP.md) |
| is given a new password by an administrator | the User Manager: **Generate Random Password** makes one of the length set in the rules |

A reset by mail is as safe as the user's mailbox. For accounts that matter, turn it off and let an administrator do resets.

## How the server keeps passwords

A password is stored as a **hash**: a value from which the password cannot be read back, only checked. The method is chosen in [How passwords are stored](Prefs-Encryption-Passwords.md).

| Method | Use |
|---|---|
| **PBKDF2**, the one a new server uses | yes |
| the older hashes (SHA, MD5, crypt forms) | they are read, so that users of an earlier version can still log in, and are replaced by the current method the next time each user logs in |
| stored readable (encrypted, not hashed) | only where the server must hand the password on, as with a login that is passed to another system. Then give the server a key of its own: [Secrets on disk](Security-Secrets-at-Rest.md). |

A **salt** makes equal passwords look different in the store: see the same Preferences page.

Nobody can read a hashed password out of the server: not an administrator, not the API, not support. A forgotten password is replaced, never looked up.

## Where passwords never show

The log masks them, the admin pages do not echo them, and the web interface seals them in the browser before they are sent: see [What never reaches a log](Security-Log-Privacy.md).

## Guessing

Wrong passwords are counted per address and per account:

| Protection | Where |
|---|---|
| an address that fails too often is banned for a time | [Bans and hammering](Security-Bans.md) |
| an account is disabled after so many failed logins | [Restrictions](Users-Restrictions.md) of the user |
| a pause that grows with failures | the same Banning settings |

## Good practice

- One set of rules on `default`, a stricter one on the template of administrators.
- A second factor matters more than any password rule: [Two-factor sign-in](Security-Two-Factor.md).
- No shared accounts. One person, one account; one script, one account.
- When somebody leaves, disable the account at once and delete it later.
