PHP code example of prasanth-j / otpify

1. Go to this page and download the library: Download prasanth-j/otpify 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/ */

    

prasanth-j / otpify example snippets


return [
    'driver'   => env('OTPIFY_DRIVER', 'database'),
    'digits'   => env('OTPIFY_DIGITS', 6),
    'validity' => env('OTPIFY_VALIDITY', 10), // minutes
    'type'     => env('OTPIFY_TYPE', 'numeric'), // numeric|alpha|alphanumeric
    'cache'    => [
        'prefix' => 'otpify',
        'store'  => env('OTPIFY_CACHE_STORE', null), // null = default cache store
    ],
];

use PrasanthJ\Otpify\Facades\Otpify;

$result = Otpify::generate('[email protected]'); // purpose defaults to "default"

$result->token;     // e.g. "482913" — send this to the user
$result->expiresAt; // Carbon instance
$result->status;    // "generated"

$result = Otpify::generate('[email protected]', 'login', [
    'digits'   => 4,
    'validity' => 5,          // minutes
    'type'     => 'alphanumeric',
]);

$result = Otpify::validate('[email protected]', $token, 'login');

if ($result->isValid()) {
    // proceed
}

Otpify::invalidate('[email protected]', 'login'); // returns bool

$result = Otpify::resend('[email protected]', 'login', ['validity' => 10]);

Otpify::generate('[email protected]', 'login');
Otpify::generate('[email protected]', '2fa');

use Illuminate\Support\Facades\Validator;
use PrasanthJ\Otpify\Rules\OtpRule;

$validator = Validator::make($request->all(), [
    'otp' => ['

use PrasanthJ\Otpify\Events\OtpGenerated;

Event::listen(function (OtpGenerated $event) {
    // send $event->token to $event->identifier via SMS/email
});

use Illuminate\Support\Facades\RateLimiter;
use PrasanthJ\Otpify\Facades\Otpify;

$key = 'otp-generate:' . $request->ip() . ':' . $request->input('email');

if (RateLimiter::tooManyAttempts($key, 5)) {
    abort(429, 'Too many OTP requests. Please try again later.');
}

RateLimiter::hit($key, 60); // 1 attempt per minute window, 5 max

$result = Otpify::generate($request->input('email'));

Schedule::command('otpify:clean')->daily();
bash
php artisan vendor:publish --tag=otpify-config
bash
php artisan vendor:publish --tag=otpify-migrations
php artisan migrate
bash
php artisan otpify:clean