Why 2FA?
Nowadays we have noticed that many of the websites or applications that we access offer the option to activate an extra layer of security called Two Factor Authentication, better known as 2FA. Most of our lives happen on our mobile devices and laptops, so it’s not a secret that cyber-thieves would like to gain access to our personal and financial data. This is why adding an extra layer for protecting logins is worth it.
2FA is an extra layer of security to make sure that someone that is trying to gain access to an account is who they say they are. The first layer is generally a combination of a username and password, and the second layer could ask for a code that is sent to your phone, a fingerprint scan or the name of your best friend.
Currently 2FA has become a security standard in the digital world.
How does it work?
First the user will enter his username and password, then instead of getting in immediately into the system, he will be required to provide additional information. Which could be one of the following options or factors:
-
Something you know : This could be a password, a personal identification number (PIN), answers to a secret question or a specific keystroke pattern.
-
Something you have: This is something the user owns, a physical device, like a mobile phone, an id card, an usb stick, a token, etc.
-
Something you are: This could be face or voice recognition, retina scan, fingerprint, DNA, handwriting.
CakeDC Users Plugin and 2FA
There are various ways to implement Time-based One-Time Password (TOTP), Short Message Service (SMS), Electronic Mail (Email), Universal Second Factor (U2F). CakeDC Users Plugin provides the ability to enable in your site TOTP or U2F.
TOTP Google Authenticator
Enabling 2FA Google Authenticator in CakeDC Users Plugin is quite easy, it just takes a few minutes. In case you have not installed CakeDC Users Plugin in your application, follow the installation steps described here.
Once you have installed the plugin and your basic login is working, you just need to do the following:
-
Run the next command:
composer require robthree/twofactorauth
-
In Application::pluginBootstrap() add the following:
Configure::write('OneTimePasswordAuthenticator.login', true);
Once you have 2FA enabled in your site, when you try to login will happen next
-
Type your username and password.
-
You proceed to the next step where you are asked for the authentication code
-
First time you will be shown a QR code that you need to scan from your authenticator application.
-
Next time you will only get the input to type your authentication code
-
-
You open the authenticator application to get a secondary code called a one-time password (OTP)—usually six characters in length. There are many options in the market for the authenticator application, some of the most used are: Google Authenticator, Duo Mobile, FreeOTP etc.
- You type the 6-digit code into the website, and you’re in!
FIDO U2F
If you want something more solid and reliable, then you could use U2F (Universal 2nd Factor) standard created by the FIDO Alliance. With this kind of authentication you use a physical security key, and insert that into your PC, touch the key’s button, and you’re “automatically” logged in.
U2F standard was implemented in CakeDC Users Plugin by using the YubiKey, the most famous and common example of U2F.
To enable 2FA via Yubico follow the next steps:
-
Run the next command:
composer require yubico/u2flib-server:^1.0
-
In Application::pluginBootstrap() add the following:
Configure::write(‘U2f.enabled’, true);
Yubico is a hardware based 2FA, it’s a small device with one end that slots into a standard Type-A USB port. You just need to Insert your YubiKey and touch it! You won’t need to manually enter the code.
Take into account that you will need to use https to be able to use 2FA features in your applicatins.
So, what to choose for two-factor authentication? There is no universal answer, it will depend on the level of security you are expecting, but start protecting your account by enabling 2FA! In this article you could noticed how easy is to enable 2FA in any CakePHP application by using CakeDC Users Plugin.
References:
https://github.com/CakeDC/users
https://en.wikipedia.org/wiki/Multi-factor_authentication
https://en.wikipedia.org/wiki/One-time_password
https://en.wikipedia.org/wiki/FIDO_Alliance
https://en.wikipedia.org/wiki/Universal_2nd_Factor