Documentation Index
Fetch the complete documentation index at: https://filamentphp.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
Introduction
Users in Filament can sign in with their email address and password by default. However, you can enable multi-factor authentication (MFA) to add an extra layer of security to your users’ accounts. When MFA is enabled, users must perform an extra step before they are authenticated and have access to the application. Filament includes two methods of MFA which you can enable out of the box:- App authentication uses a Google Authenticator-compatible app (such as the Google Authenticator, Authy, or Microsoft Authenticator apps) to generate a time-based one-time password (TOTP) that is used to verify the user.
- Email authentication sends a one-time code to the user’s email address, which they must enter to verify their identity.
App authentication
To enable app authentication in a panel, you must first add a new column to yourusers table (or whichever table is being used for your “authenticatable” Eloquent model in this panel). The column needs to store the secret key used to generate and verify the time-based one-time passwords. It can be a normal text() column in a migration:
User model, you should implement the HasAppAuthentication interface and use the InteractsWithAppAuthentication trait which provides the necessary methods to interact with the secret code and other information about the integration:
multiFactorAuthentication() method in the configuration, and pass a AppAuthentication instance to it:
Setting up app recovery codes
If your users lose access to their two-factor authentication app, they will be unable to sign in to your application. To prevent this, you can generate a set of recovery codes that users can use to sign in if they lose access to their two-factor authentication app. In a similar way to theapp_authentication_secret column, you should add a new column to your users table (or whichever table is being used for your “authenticatable” Eloquent model in this panel). The column needs to store the recovery codes. It can be a normal text() column in a migration:
HasAppAuthenticationRecovery interface on the User model and use the InteractsWithAppAuthenticationRecovery trait which provides Filament with the necessary methods to interact with the recovery codes:
recoverable() method to the AppAuthentication instance in the multiFactorAuthentication() method in the configuration:
Changing the number of recovery codes that are generated
By default, Filament generates 8 recovery codes for each user. If you want to change this, you can use therecoveryCodeCount() method on the AppAuthentication instance in the multiFactorAuthentication() method in the configuration:
Preventing users from regenerating their recovery codes
By default, users can visit their profile to regenerate their recovery codes. If you want to prevent this, you can use theregenerableRecoveryCodes(false) method on the AppAuthentication instance in the multiFactorAuthentication() method in the configuration:
Changing the app code expiration time
App codes are issued using a time-based one-time password (TOTP) algorithm, which means that they are only valid for a short period of time before and after the time they are generated. The time is defined in a “window” of time. By default, Filament uses an expiration window of8, which creates a 4-minute validity period on either side of the generation time (8 minutes in total).
To change the window, for example to only be valid for 2 minutes after it is generated, you can use the codeWindow() method on the AppAuthentication instance, set to 4:
Customizing the app authentication brand name
Each app authentication integration has a “brand name” that is displayed in the authentication app. By default, this is the name of your app. If you want to change this, you can use thebrandName() method on the AppAuthentication instance in the multiFactorAuthentication() method in the configuration:
Email authentication
Email authentication sends the user one-time codes to their email address, which they must enter to verify their identity. To enable email authentication in a panel, you must first add a new column to yourusers table (or whichever table is being used for your “authenticatable” Eloquent model in this panel). The column needs to store a boolean indicating whether or not email authentication is enabled:
HasEmailAuthentication interface on the User model and use the InteractsWithEmailAuthentication trait which provides Filament with the necessary methods to interact with the column that indicates whether or not email authentication is enabled:
multiFactorAuthentication() method in the configuration, and pass an EmailAuthentication instance to it:
Changing the email code expiration time
Email codes are issued with a lifetime of 4 minutes, after which they expire. To change the expiration period, for example to only be valid for 2 minutes after codes are generated, you can use thecodeExpiryMinutes() method on the EmailAuthentication instance, set to 2:
Requiring multi-factor authentication
By default, users are not required to set up multi-factor authentication. You can require users to configure it by passingisRequired: true as a parameter to the multiFactorAuthentication() method in the configuration:
Security notes about multi-factor authentication
In Filament, the multi-factor authentication process occurs before the user is actually authenticated into the app. This allows you to be sure that no users can authenticate and access the app without passing the multi-factor authentication step. You do not need to remember to add middleware to any of your authenticated routes to ensure that users completed the multi-factor authentication step. However, if you have other parts of your Laravel app that authenticate users, please bear in mind that they will not be challenged for multi-factor authentication if they are already authenticated elsewhere and then visit the panel, unless multi-factor authentication is required and they have not set it up yet.Concurrent recovery code submissions
When a user signs in with a recovery code, Filament’sverifyRecoveryCode() method wraps the read-validate-write sequence in a per-user Cache::lock and a database transaction with a lockForUpdate() row lock on the user’s row. The cache lock serializes concurrent submissions across PHP workers regardless of the underlying database driver, so two parallel sign-in requests cannot both consume the same code or resurrect a just-consumed code from a stale snapshot — even when the storage is a non-SQL store, a different database connection, or a driver without SELECT ... FOR UPDATE support (such as SQLite).