Documentation
First steps / Turn on two-factor authentication

Turn on two-factor authentication

Ask for a code from an authenticator app at each sign-in, keep recovery codes, and help a user who lost their phone.

Since v1.6.5, each user can protect their account with two-factor authentication (TOTP). Once it is on, the password is no longer enough: each sign-in also asks for a 6-digit code generated by an app such as Bitwarden, Aegis, 1Password or Google Authenticator.

Two-factor authentication is optional and personal: every user, admin or read-only, turns it on for their own account.

Turn it on

Open your profile menu at the bottom of the sidebar, choose Settings, then Two-factor auth.

  1. Choose Turn on.
  2. Scan the QR code with your authenticator app. If you cannot scan it, copy the Key for a manual entry into the app.
  3. Enter the 6-digit code shown by the app, then choose Confirm and turn on.
  4. Save your recovery codes: see Recovery codes.

Turning it on signs you out of your other sessions. The current one stays open.

With Bitwarden, edit the login item of your instance, then scan the QR code or paste the key into the Authenticator key (TOTP) field. Bitwarden then fills in the code at sign-in.

The entry created in the app is named after the TWO_FACTOR_ISSUER variable, Uptime Kotlin by default, followed by your email. Change it when you run several instances, to tell them apart. See Configuration.

Sign in

After the email and password, the login page asks for the code from the app. Choose Use a recovery code if you do not have the app at hand.

  • The sign-in step expires after 5 minutes: enter your password again.
  • A code works only once. A code from the previous or next 30 seconds is accepted, to absorb a clock a little off.
  • After 10 invalid codes in 15 minutes, the account refuses codes for a while: wait 15 minutes, then sign in again.

Recovery codes

When you turn on two-factor authentication, Uptime Kotlin shows 10 recovery codes, such as ab3de-fg7hk. Each one replaces a code from the app, once, if you lose access to it.

  • They are shown only once: download them or choose Copy all, and keep them somewhere safe, for example in your password manager.
  • The Two-factor auth tab shows how many are left.
  • New recovery codes generates 10 new ones and makes the old ones stop working. It asks for a code from the app, not a recovery code.

Turn it off

In the Two-factor auth tab, choose Turn off, then enter your current password and a code from the app or a recovery code. Your password alone is then enough to sign in, and the recovery codes are deleted.

A user lost their phone

A user who lost both the app and the recovery codes cannot sign in. An admin turns their two-factor authentication off:

  1. In Settings, Users, the users who have turned it on carry a 2FA badge.
  2. On the line of the user, choose Turn off two-factor authentication, then confirm.
  3. The user signs in with their password only, then turns it on again from their profile.

You cannot turn off your own two-factor authentication this way: do it from your profile.

If the locked-out user is the only admin, use RESET_ADMIN_PASSWORD: it also turns off the two-factor authentication of the account.

Good to know

  • The secret of each user is encrypted with the ENCRYPTION_MASTER_KEY, like the other secrets, and follows a master key rotation. Recovery codes are stored hashed.
  • Two-factor authentication is not part of a backup: users are not exported.
  • The codes follow the standard TOTP: SHA-1, 6 digits, 30 seconds. Any authenticator app works.

API

Method Endpoint Body
GET /api/profile/two-factor Status, and the number of recovery codes left.
POST /api/profile/two-factor/setup Returns the secret and the otpauth:// URI.
POST /api/profile/two-factor/enable code. Returns the recovery codes.
POST /api/profile/two-factor/recovery-codes code from the app. Returns new recovery codes.
POST /api/profile/two-factor/disable password and code (from the app or a recovery code).
POST /api/users/{userId}/disable-two-factor Admin only. Turns off the two-factor authentication of a user.

When two-factor authentication is on, POST /api/auth/login answers mfaRequired: true and a challengeToken instead of the tokens. Send that token and the code to POST /api/auth/login/totp to get them.

Suggest a change on GitHub