This PHP library provides two-factor authentication (2FA) functionality for Zend Framework 1 applications. It allows for secure user login by requiring an additional step of verification, enhancing application security.
-
Create an Action:
Implement an action in your backend where 2FA will be handled. -
Instantiate the 2FA Service:
$this->tfa = new \Zend\TwoFactorAuth();
- Set Mail Configuration:
$this->tfa->setMailConfig([
'transport' => [], // Mail transport settings
'subject' => '', // Email subject for 2FA codes
'from' => ['email' => '', 'name' => ''], // Sender details
'template' => [] // Email template configuration
]);
- Initialize the 2FA Service: Call the init method with a callback function to validate the user:
$this->tfa->init([$this, 'checkUser']);
- Implement the checkUser Method:
This method should handle user validation and error management using
Zend\Util\ResponseUtil
.
-
Copy the Client Folder:
Copy the2fa-client
folder located insidesrc
and place it in yourpublic/js/
directory. -
Initialize the 2FA Client:
Use the following JavaScript code to initialize the 2FA client:
zfTwoFactorAuth.init(apiUrl, data, 'glass-theme', (loginFormData, url) => {
// Handle the login callback here
});
apiUrl
: The API endpoint previously created for 2FA.data
: The login form fields converted into an object, e.g., {username: 'joe', password: 123456}.glass-theme
: The style theme for the 2FA modal. Available themes are:glass-theme
cds-theme
Callback Function
: Handles the login URL and sanitized parameters.
- Zend Framework 1
- PHP 8.0 or higher
- Composer for dependency management
composer require fragotesac/zf1-2fa