tech-ed / simpl-otp
A simple and lightweight Laravel package for generating and verifying one-time passwords (OTPs), enhancing authentication security in your Laravel applications.
Installs: 484
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/tech-ed/simpl-otp
Requires
- php: ^8.2
- laravel/framework: ^11.0|^12.0
README
A Laravel package for simple OTP generation and validation with built-in Blade frontend scaffolding.
Features
- 🔐 Generate and validate OTPs
- 🎨 Ready-to-use Blade views
- 📧 Email notification support
- ⚙️ Configurable settings
- 🚀 Easy integration
Quick Start
Installation
composer require tech-ed/simpl-otp php artisan migrate
Basic Usage
use TechEd\SimplOtp\SimplOtp; // Generate OTP $otp = SimplOtp::generate('user@example.com'); // Validate OTP $result = SimplOtp::validate('user@example.com', '1234');
Configuration
Publish the config file:
php artisan vendor:publish --provider="TechEd\SimplOtp\SimplOtpServiceProvider" --tag="config"
Configure OTP settings in config/simplotp.php:
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', ] ];
Frontend Views
Setup
php artisan simplotp:publish-frontend
Routes
- Generate OTP:
/simplotp/generate - Verify OTP:
/simplotp/verify
Using in Your Controllers
return view('simplotp::generate'); return view('simplotp::verify');
Customization
The views are published to resources/views/vendor/simplotp/ and include Bootstrap styling. You can customize them to match your application's design.
Email Notifications
Publish Email Template
php artisan vendor:publish --provider="TechEd\SimplOtp\SimplOtpServiceProvider" --tag="email"
Send OTP via Email
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)); }
Support
If SimplOtp has been helpful to you and you'd like to support its development, consider buying the developer a cup of coffee! ☕
Your support is greatly appreciated and helps in maintaining and improving SimplOtp for the Laravel community.