PHP code example of teckwei1993 / laravel-otp

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

    

teckwei1993 / laravel-otp example snippets


Teckwei1993\Otp\OtpServiceProvider::class

'Otp' => Teckwei1993\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 Teckwei1993\Otp\Rules\OtpValidate;

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

// Otp class

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

// in a `FormRequest`

use Teckwei1993\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 Teckwei1993\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 Teckwei1993\Otp\Rules\OtpValidate;

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

// validate

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

// in controller

use Teckwei1993\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="Teckwei1993\Otp\OtpServiceProvider"