Download the PHP package andrej-griniuk/cakephp-two-factor-auth without Composer
On this page you can find all versions of the php package andrej-griniuk/cakephp-two-factor-auth. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download andrej-griniuk/cakephp-two-factor-auth
More information about andrej-griniuk/cakephp-two-factor-auth
Files in andrej-griniuk/cakephp-two-factor-auth
Package cakephp-two-factor-auth
Short Description CakePHP auth component and provider fot two-factor authentication
License MIT
Homepage http://github.com/andrej-griniuk/cakephp-two-factor-auth
Informations about the package cakephp-two-factor-auth
TwoFactorAuth plugin for CakePHP
This plugin provides two factor authentication functionality using RobThree/TwoFactorAuth library.
Basically, it works similar way CakePHP FormAuthenticate
does. After submitting correct username/password, if the user has secret
field set, he will be asked to enter a one-time code.
Attention: it only provides authenticate provider and component and does not take care of users signup, management etc.
Requirements
- CakePHP 5.0+ (use ^1.3 version for CakePHP <3.7, ^2.0 version for CakePHP 3.x, ^3.0 version for CakePHP 4.x)
Installation
You can install this plugin into your CakePHP application using Composer.
Usage
First of all you need to add secret
field to your users table (field name can be changed to TwoFactorAuth.Form
authenticator configuration).
Second, you need to load the plugin in your Application.php
Alternatively, execute the following line:
You can see the default config values here and find out what do they mean here. To overwrite them, pass them as TwoFactorForm
authenticator values.
Then you need to set up authentication in your Application.php as you would normally do it, but using TwoFactorForm
authenticator instead of Form
, e.g.:
Next, in your AppController load the Authentication
and TwoFactorAuth
components:
Once you have the middleware applied to your application you’ll need a way for users to login. A simplistic UsersController
would look like:
And verify.php
would look like:
Basically, it works same way CakePHP Authentication.Form
authenticator does.
After entering correct username/password combination, if the user has secret
field (can be overwritten via TwoFactorAuth.TwoFactorForm
configuration) set he will be redirected to the verify
action where he is asked to enter a one-time code.
There is no logic behind this action, it only renders the form that has to be submitted to the loginAction
again with code
field set.
You can access the RobThree\Auth\TwoFactorAuth instance from your controller via $this->TwoFactorAuth->getTfa()
or call some of the methods directly on TwoFactorAuth
component. For example, you can generate user's secret and get QR code data URI for it this way:
Then display it in your view:
See the library page for full documentation: https://github.com/RobThree/TwoFactorAuth
Bugs & Feedback
https://github.com/andrej-griniuk/cakephp-two-factor-auth/issues
Credits
https://github.com/RobThree/TwoFactorAuth
License
Copyright (c) 2020, Andrej Griniuk and licensed under The MIT License.
All versions of cakephp-two-factor-auth with dependencies
cakephp/cakephp Version ^5.0
cakephp/authentication Version ^3.0
robthree/twofactorauth Version ^2.1