{% extends "base.html" %} {% from "components/ui.html" import ago, card, copy_button, csrf_field, dialog_button, dialog_buttons, empty, form_dialog, icon, related, row_form, tick, tick_all, toggle with context %} {% from "components/factor.html" import second_step with context %} {% block title %}Second factor ยท {{ APP_NAME }}{% endblock %} {% block heading %}Second factor{% endblock %} {% block subheading %}
{% if factor.totp or factor.passkeys %}on Signing in to this UI asks for your password and a second step.{% else %}off Your password alone signs you in to this UI. Add a device or a passkey to turn it on.{% endif %}
{% endblock %} {% block content %} {% set devices = factor.totp %} {% set keys = factor.passkeys %} {% set on = devices or keys %} {% if codes %}

Your new recovery codes

shown this once

Each signs you in once in place of a code of a device or a passkey, e.g. when a phone is lost. Keep them apart from your devices, in a password manager or on paper.

    {% for code in codes %}
  • {{ code }}
  • {% endfor %}
{{ copy_button("recovery-codes", "Copy all codes") }}
{% endif %} {% if qr %} {% call card("Scan the code for " ~ setup.name, meta="With an authenticator app, within " ~ minutes ~ " minutes.") %}

1. Scan this code with your authenticator app.

QR code of the device {{ setup.name }}

Or type in this key:

{{ secret }}{{ copy_button("totp-key", "Copy the key") }}
{{ csrf_field() }}
{{ csrf_field() }}
{% endcall %} {% endif %} {% if making %} {% call card("Make the passkey " ~ making.name, meta="With this device, a security key or a password manager, within " ~ minutes ~ " minutes.") %}

The browser asks where to keep it, and for your PIN, fingerprint or face.

{{ csrf_field() }}
{{ csrf_field() }}
{% endcall %} {% endif %} {% set can_add = not qr and devices | length < max_devices %} {% call related("Authenticator app (TOTP)", count=devices | length, meta=("A code from any of them works." if devices else "Any authenticator app works."), add=("Add a device" if can_add else None), add_dialog="add-device") %} {% if devices | length > 1 %}
Ticked devices {{ dialog_button("remove-ticked", "Remove", alone=False) }}
{% endif %}
{% if devices | length > 1 %}{% endif %} {% set columns = 5 if devices | length > 1 else 4 %} {% for device in devices %} {% if devices | length > 1 %}{% endif %} {% call row_form("rename-" ~ device.id, columns) %} {{ csrf_field() }}
{% endcall %} {% endfor %}
{{ tick_all("devices-batch", "device") }}NameAddedLast usedActions
{{ tick("devices-batch", "device", device.id, "Tick " ~ device.name) }}{{ device.name }} {{ ago(device.created_at) }} {{ ago(device.last_used_at) }} {{ toggle("rename-" ~ device.id, "Rename", "pencil", name="Rename " ~ device.name) }} {{ dialog_button("remove-" ~ device.id, "Remove", name="Remove " ~ device.name) }}
{% if not devices %}{{ empty("No device yet. Any authenticator app works: add a phone or a tablet and scan its QR code." ~ ("" if on else " The first one brings ten recovery codes.")) }}{% endif %}
{% endcall %} {% set can_make = passkeys_work and not making and keys | length < max_devices %} {% call related("Passkeys", count=keys | length, meta=("Any of them works." if keys else "Kept on a device, a security key or in a password manager."), add=("Add a passkey" if can_make else None), add_dialog="add-passkey") %}
{% for key in keys %} {% call row_form("rename-" ~ key.id, 4) %} {{ csrf_field() }}
{% endcall %} {% endfor %}
NameAddedLast usedActions
{{ key.name }} {{ ago(key.created_at) }} {{ ago(key.last_used_at) }} {{ toggle("rename-" ~ key.id, "Rename", "pencil", name="Rename " ~ key.name) }} {{ dialog_button("remove-" ~ key.id, "Remove", name="Remove " ~ key.name) }}
{% if not passkeys_work %}
Passkeys work at a name over HTTPS, or at localhost. Open this page at the public address of the service to add one.
{% elif not keys %}{{ empty("No passkey yet. A laptop or a phone with a PIN or a fingerprint, a security key or a password manager can keep one.") }}{% endif %}
{% endcall %} {% macro confirm_fields(id, step=True) %}
{% if caller is defined %}{{ caller() }}{% endif %}
{% if step %}{{ second_step(id, ways) }}{% endif %}
{% endmacro %} {% if can_add %} {% call form_dialog("add-device", "Add a device", "The next step shows its QR code." ~ ("" if on else " Then ten recovery codes, once.") ~ " Adding a device signs out your other sessions.") %}
{{ csrf_field() }} {% call confirm_fields("add", step=on) %}
{% endcall %} {{ dialog_buttons("Next", icon="check-lg", danger=False) }}
{% endcall %} {% endif %} {% if can_make %} {% call form_dialog("add-passkey", "Add a passkey", "The next step asks the browser to make it." ~ ("" if on else " Then ten recovery codes, once.") ~ " Adding a passkey signs out your other sessions.") %}
{{ csrf_field() }} {% call confirm_fields("passkey", step=on) %}
{% endcall %} {{ dialog_buttons("Next", icon="check-lg", danger=False) }}
{% endcall %} {% endif %} {% set last = (devices | length) + (keys | length) == 1 %} {% for device in devices %} {% call form_dialog("remove-" ~ device.id, "Remove " ~ device.name ~ "?", "Its codes stop working." ~ (" It is the last device: the second factor is off then, and the recovery codes go with it." if last else "")) %}
{{ csrf_field() }} {{ confirm_fields("remove-" ~ device.id) }} {{ dialog_buttons("Remove device") }}
{% endcall %} {% endfor %} {% if devices | length > 1 %} {% call form_dialog("remove-ticked", "Remove the ticked devices?", "Their codes stop working. With every device ticked and no passkey, the second factor is off, and the recovery codes go with it.") %}
{{ csrf_field() }} {{ confirm_fields("remove-ticked") }} {{ dialog_buttons("Remove devices") }}
{% endcall %} {% endif %} {% for key in keys %} {% call form_dialog("remove-" ~ key.id, "Remove " ~ key.name ~ "?", "It no longer signs you in. Remove it from the device or the password manager as well." ~ (" It is the last device: the second factor is off then, and the recovery codes go with it." if last else "")) %}
{{ csrf_field() }} {{ confirm_fields("remove-" ~ key.id) }} {{ dialog_buttons("Remove passkey") }}
{% endcall %} {% endfor %} {% if on %} {% call related("Recovery codes", meta=factor.recovery_codes_left ~ " left. New ones replace them all.", add="Make new codes", add_dialog="new-codes", add_icon="arrow-repeat") %} {% if factor.recovery_codes_left <= 2 %}
{% if factor.recovery_codes_left == 0 %}
No recovery codes are left. Make new ones.
{% else %}
Few recovery codes are left. Make new ones.
{% endif %}
{% endif %} {% endcall %} {% call form_dialog("new-codes", "Make new recovery codes?", "They replace the ones left, which stop working.") %}
{{ csrf_field() }} {{ confirm_fields("codes") }} {{ dialog_buttons("Make new codes", icon="check-lg", danger=False) }}
{% endcall %} {% endif %} {% endblock %}