# Two-factor sign-in

With two-factor sign-in, a password alone is not enough: the user also proves that they hold something, a phone or a key. A stolen or guessed password then opens nothing.

CrushMFT knows three second factors:

| Factor | The user | Page |
|---|---|---|
| an **authenticator app** (Google Authenticator, Microsoft Authenticator and the like) | types the six digits the app shows | this page |
| a **code sent** by mail or SMS | types the code they receive | [One-time codes by mail and SMS](Security-OTP.md) |
| a **passkey** or security key | touches the key, or uses fingerprint or face on their device | [Passkeys and security keys](Security-WebAuthn.md) |

Two-factor sign-in is an Enterprise feature.

## The switches

| Where | Setting | What it does |
|---|---|---|
| the server: **OTP Settings** in [General Settings](Prefs-General.md#otp-settings) | **Validated Logins?** | the main switch. Off: nobody is asked for a code, whatever their account says. |
| | **Google Authenticator Auto Enable** | a user who sets up an app is asked for codes from then on, without an administrator turning it on for them |
| the user: [Setup](Users-Setup.md#a-second-factor) | **Two factor OTP/SMS** | asks this user for a code: on **All** protocols, or on those you tick |
| | **OTP auto valid for** | for how many days the same device is not asked again after a code was accepted |
| | **Two factor authentication secret**, **Clear Secret** | the secret of the user's app; clearing it makes the user set the app up again |
| the user: [Customizations](Users-WebInterface-Customizations.md) | **Enable two factor registration** | shows the set-up of an app in the user's **User Options** |
| | **Two Factor: force Google Authenticator setup** | the user must set up an app at their next login, before anything else |
| | **User Options: Show only Google Authenticator setup** | shows nothing else in User Options |

Set the user's switches on `default` or on a template to give them to everybody at once.

## Setting up an authenticator app

The user needs an app on their phone and one minute.

1. They log in to the web interface as usual and open **User Options**. With the forced set-up, the window opens by itself.
2. They press the button to show the QR code and scan it with the app. The code on the screen is good for a short time; if it runs out, they ask for a new one.
3. They type the six digits the app now shows, to confirm. That proves the app has the secret.
4. The server stores the secret with the account.

From the next login on, after the password, the web interface asks for the code.

A user cannot remove or replace the secret themselves. When a phone is lost, an administrator presses **Clear Secret** in the User Manager, and the user sets up the new phone at the next login.

## On other protocols

| Protocol | How the code is given |
|---|---|
| web interface | a field after the password |
| SFTP | a prompt, "keyboard interactive": see [SSH keys](Security-SSH-Keys.md#one-time-codes-over-sftp) |
| FTP | added to the password |
| WebDAV, S3, SMB | no way to ask. Leave them out of the user's two-factor protocols, or do not allow them for that user. |

Which protocols ask for a code by themselves once a user has an app is the server setting `twofactor_secret_auto_otp_enable_protocols`.

## Rolling it out

1. Turn on **Validated Logins?** and decide on **Google Authenticator Auto Enable**.
2. Start with the administrators: put **Enable two factor registration** and the forced set-up on their template.
3. Tell users beforehand, with the name of an app and a sentence on what will happen.
4. Then the same for the users' templates, group by group.
5. Decide what scripts do: accounts of their own, with keys or tokens, without a second factor, restricted by address.

## Things to know

- The codes of an app depend on the time. The server's clock must be right; let the machine keep it with a time service.
- Behind a DMZ server, **Validated Logins?** must be on on the DMZ server as well.
- A second factor on the account does not protect the user's **shares**: a share link is its own login.
- Keep one way in for yourself that does not depend on a phone: a second administrator, or access to the server machine.
