Download the PHP package mkd/laravel-otp without Composer
On this page you can find all versions of the php package mkd/laravel-otp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mkd/laravel-otp
More information about mkd/laravel-otp
Files in mkd/laravel-otp
Package laravel-otp
Short Description An advanced, customizable OTP (One-Time Password) verification system for Laravel applications, supporting hashed token and custom validation methods.
License MIT
Homepage https://github.com/mustafakhaleddev/laravel-advanced-otp
Informations about the package laravel-otp
Laravel OTP
A simple Laravel package for generating and verifying One-Time Passwords (OTPs) using TOTP (Time-based One-Time Password) and HOTP (HMAC-based One-Time Password) algorithms.
Installation
You can install the package via Composer:
Example
Scan This QR Code using Authenticator app
Here's a simple example demonstrating how to generate and verify an OTP:
Usage
Creating an Instance
You can create an instance of the LaravelOTP
class by providing a secret key:
Public Methods
now(): string
Returns the current TOTP for the current timeframe.
last(): string
Returns the TOTP for the previous timeframe (30 seconds earlier).
next(): string
Returns the TOTP for the next timeframe (30 seconds later).
at(int $offset = 0): string
Returns the TOTP for a custom timeframe based on the provided offset. An offset of 0
returns the current TOTP, -1
returns the last OTP, and 1
returns the next OTP.
generateSecretKey(): string
Generates a new secret key.
atCounter(int $counter): string
Returns the HOTP for a specific counter value.
verifyTOTP(string $otp, string|null $secret = null): bool
Verifies a given TOTP against the current, previous, and next timeframes. If a secret key is provided, it overrides the current secret.
verifyHOTP(string $otp, int $counter, string|null $secret = null): bool
Verifies a given HOTP against a specific counter. If a secret key is provided, it overrides the current secret.
Google Authenticator Compatible
generateUrl(string $label, string $issuer, string $secretKey = null, int $counter = null): string
Generates an OTP Auth URL for use in generating a QR code. This URL can be used by OTP apps like Google Authenticator.
- Parameters:
string $label
: A unique identifier for the OTP (usually the user's email or username).string $issuer
: The name of your application (used as the issuer for the OTP).string|null $secretKey
: An optional secret key. If not provided, the instance's secret key will be used.int|null $counter
: An optional counter for HOTP. If provided, the method will generate an HOTP URL instead of TOTP.
Usage Example:
License
This package is licensed under the MIT License. See the LICENSE file for more information.