PHP code example of soiposervices / laravel-otp

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

    

soiposervices / laravel-otp example snippets


SoipoServices\Otp\OtpServiceProvider::class

'Otp' => SoipoServices\Otp\OtpFacade::class

Otp::generate(string $identifier)

use OTP;

// in controller

$password = Otp::generate('reg:[email protected]');

Otp::validate(string $identifier, string $password)

use OTP;

// in controller

$result = Otp::validate('reg:[email protected]', '123456');

// in a `FormRequest`

use SoipoServices\Otp\Rules\OtpValidate;

public function rules()
{
    return [
        'code' => ['')]
]);

// Otp class

$result = Otp::validate('123456');

// in a `FormRequest`

use SoipoServices\Otp\Rules\OtpValidate;

public function rules()
{
    return [
        'code' => ['

$password = Otp::setLength(8)->setFormat('string')->setExpires(60)->setRepeated(false)->generate('identifier-key-here');

// or array option

$password = Otp::generate('identifier-key-here', [
    'length' => 8,
    'format' => 'string',
    'expires' => 60,
    'repeated' => false
]);

$password = Otp::setCustomize('12345678ABC@#$')->generate('identifier-key-here');

$password = Otp::setAttempts(3)->validate('identifier-key-here', 'password-here');

$password = Otp::setSensitive(true)->generate('identifier-key-here');

// validate

$result = Otp::setSensitive(true)->validate('identifier-key-here', 'password-here');

// in controller

use SoipoServices\Otp\Rules\OtpValidate;

$request->validate([
    'code' => ['

$password = Otp::setLength([4,3,4])->setSeparator(':')->generate('identifier-key-here');

$password = Otp::setData(['user_id' => auth()->id()])->generate('login-confirmation');

// validate

$result = Otp::setDisposable(false)->validate('login-confirmation', 'password-here');

// in controller

use SoipoServices\Otp\Rules\OtpValidate;

$request->validate([
    'code' => ['

// validate

$result = Otp::setSkip(true)->validate('identifier-key-here', 'password-here');

// in controller

use SoipoServices\Otp\Rules\OtpValidate;

$request->validate([
    'code' => ['

Otp::forget('identifier-key-here');

Otp::forget('identifier-key-here', 'password-here');

Otp::resetAttempt('identifier-key-here');
bash
php artisan vendor:publish --provider="SoipoServices\Otp\OtpServiceProvider"