fragotesac / zf1-2fa
Zend Framework 1 2FA component
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Language:HTML
Requires
- php: ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0
- fragotesac/zf1: 0.0.2
This package is not auto-updated.
Last update: 2025-01-15 16:06:36 UTC
README
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.
How to Use
Backend Configuration
-
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
.
Client-Side Setup
-
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.
Requirements
- Zend Framework 1
- PHP 8.0 or higher
- Composer for dependency management
Installation
composer require fragotesac/zf1-2fa