1. Go to this page and download the library: Download turahe/otp library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
return [
// Token expiry time in minutes
'expires' => 15,
// Database table name
'table' => 'otp_tokens',
// Password generator type (string, numeric, numeric-no-0)
'password_generator' => 'numeric',
// Default notification channels
'default_channels' => 'mail',
];
use Turahe\Otp\Facades\Otp;
// Generate OTP for email (default 15 minutes expiry)
$otp = Otp::generate('[email protected]');
// Generate OTP with custom expiry (10 minutes)
$otp = Otp::generate('[email protected]', 10);
// Generate OTP for phone number
$otp = Otp::generate('+1234567890', 5);
// Validate OTP
$isValid = Otp::validate('[email protected]', '123456');
if ($isValid) {
// OTP is valid and has been consumed
echo "OTP verified successfully!";
} else {
// OTP is invalid or expired
echo "Invalid or expired OTP";
}
use Turahe\Otp\Jobs\SendOtp;
// Send OTP via email
$otp = Otp::generate('[email protected]');
dispatch(new SendOtp('[email protected]', $otp));