PHP code example of tech-ed / simpl-otp

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

    

tech-ed / simpl-otp example snippets


use TechEd\SimplOtp\SimplOtp;

// Generate OTP
$otp = SimplOtp::generate('[email protected]');

// Validate OTP
$result = SimplOtp::validate('[email protected]', '1234');

return [
    'otp' => [
        'length' => 4,           // OTP length
        'type' => 'numeric',     // 'numeric' or 'alphanumeric'
        'validity' => 15,        // Validity in minutes
    ],
    'success_messages' => [
        'otp_generated' => 'OTP generated',
        'otp_valid' => 'OTP is valid',
    ],
    'error_messages' => [
        'expired_otp' => 'OTP Expired',
        'invalid_otp' => 'Invalid OTP',
        'otp_not_found' => 'OTP not found',
    ]
];

return view('simplotp::generate');
return view('simplotp::verify');

use TechEd\SimplOtp\SimplOtp;
use TechEd\SimplOtp\EmailOtpVerification;

$user = auth()->user();
$otp = SimplOtp::generate($user->email);

if ($otp->status === true) {
    $user->notify(new EmailOtpVerification($otp->token));
}
bash
php artisan vendor:publish --provider="TechEd\SimplOtp\SimplOtpServiceProvider" --tag="config"
bash
php artisan simplotp:publish-frontend
bash
php artisan vendor:publish --provider="TechEd\SimplOtp\SimplOtpServiceProvider" --tag="email"