Seamless TOTP and HOTP Integration for Laravel Applications

Submitted by mustafakhaleddev - 1 month ago

Laravel OTP is a comprehensive package that simplifies the generation and verification of Time-based One-Time Passwords (TOTP) and HMAC-based One-Time Passwords (HOTP). Whether you're building two-factor authentication or securing API access, Laravel OTP offers an easy-to-use, Google Authenticator-compatible solution. With support for TOTP and HOTP, and built-in methods for secret generation and verification, this package is perfect for adding an additional layer of security to your Laravel applications.

//Repo : https://github.com/mustafakhaleddev/laravel-otp
// Generate a secret key for the user
$secret = LaravelOTP::generateSecretKey();

//Init the service
$otpService = LaravelOTP::make($secret);

// Generate current TOTP
$currentOTP = $otpService->now();
echo "Current OTP: $currentOTP\n";

// Verify the OTP entered by the user
$isValid = $otpService->verifyTOTP($currentOTP);
echo $isValid ? "OTP is valid!" : "OTP is invalid!";