Download the PHP package kayon-ariel/totp-php without Composer
On this page you can find all versions of the php package kayon-ariel/totp-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kayon-ariel/totp-php
More information about kayon-ariel/totp-php
Files in kayon-ariel/totp-php
Package totp-php
Short Description Google Authenticator 2-factor authentication
License MIT
Informations about the package totp-php
TOTP-PHP
Introduction
TOTP-PHP is a PHP library for generating Time-based One-Time Passwords (TOTP) for two-factor authentication. This library is easy to integrate into your existing PHP applications, allowing you to enhance your security measures effectively.
TOTP-PHP is compatible with Google Authenticator and other TOTP applications, making it a great choice for implementing two-factor authentication in your projects.
For a secure installation you have to make sure that used codes cannot be reused (replay-attack). You also need to limit the number of verifications, to fight against brute-force attacks. For example you could limit the amount of verifications to 10 tries within 10 minutes for one IP address (or IPv6 block). It depends on your environment.
Features
- Generate TOTP codes compliant with RFC 6238.
- Simple for use.
- Built-in validation methods.
- Secret key generation for TOTP.
- Compatible with Google Authenticator and similar apps.
- Generate QR code payloads for easy integration with TOTP applications.
Installation
You can install the totp-php
library via Composer. Run the following command in your terminal:
Usage
Here is a simple example of how to use the library:
Generating a TOTP Code
Generating a Secret Key
You can generate a random secret key using the createSecret
method. This is useful for initializing a new user or session.
Generating a QR Code Payload
To generate a QR code payload for a TOTP secret, use the getQrCodePayload
function:
Validating a TOTP Code
You can validate a TOTP code using the verifyCode
method:
Code Generation and Verification Logic
The library uses the following methods:
createSecret(int $secretLength = 16): string
: Generates a new secret key with a specified length (minimum 16 characters).getCode(string $secret, ?int $timeSlice = null): string
: Calculates the TOTP code for a given secret key and time slice (defaults to the current time).verifyCode(string $secret, string $code, int $discrepancy = 1): bool
: Checks if the provided TOTP code matches the expected code for the secret, allowing for some time discrepancy.
License
This library incorporates code from the original PHPGangsta/GoogleAuthenticator
project:
- Copyright (c) 2012-2016, http://www.phpgangsta.de
- Author: Michael Kliewe, @PHPGangsta and contributors
- Licensed under the BSD License.
Current: Copyright (c) 2024 Kayon Ariel, provided under the MIT License.
Contributions
Contributions are welcome! Feel free to submit issues, fork the repository, and submit pull requests.
Contact
For any inquiries or feedback, you can reach out to me at [[email protected]].