codedive-io/laravel-code-verification
最新稳定版本:v1.0.2
Composer 安装命令:
composer require codedive-io/laravel-code-verification
包简介
README 文档
README
A package for issuing and verifying temporary confirmation codes for users in a Laravel application. It can be used for various purposes such as password reset, email or phone number verification, and two-factor authentication.
Key Features
- Code Issuance : Generate a unique confirmation code for a specific recipient (e.g., email, phone number)
- Code Verification : Validates whether the issued code is correct, not expired, and has not exceeded the maximum number of attempts.
- Event-Driven : Events are fired upon code issuance, verification, or revocation, allowing for easy integration with you business logic.
Installation
Install the package using Composer.
composer require codedive-io/laravel-code-verification
Database Migration
After installing the package, you need to run the migrations to create the verification_codes table. The migrations are automatically loaded by the service provider.
php artisan migrate
Usage
1. Code Issuance
Use the issue method of the CodeVerificationService to issue a confirmation code.
Using the Service
use Codedive\LaravelCodeVerification\CodeVerificationService; $service = app(CodeVerificationService::class); $verificationCode = $service->issue( $receiver = 'user@example.com', $purpose = 'verify_email', $userId = 1 )
Using the Facades
use Codedive\LaravelCodeVerification\CodeVerification; CodeVerification::issue( $receiver = 'user@example.com', $purpose = 'verify_email', $userId = 1 );
2. Code Verification
Use the verify method to validate the code entered by the user.
Using the Services
use Codedive\LaravelCodeVerification\CodeVerificationService; $service = app(CodeVerificationService::class); $isVerified = $service->verify( $receiver = 'user@example.com', $purpose = 'verify_email', $user_id = 1, $code = '123456' ); if ($isVerified) { // The code was successfully verified } else { // Code verification failed }
Using the Facades
use Codedive\LaravelCodeVerification\CodeVerification; $isVerified = CodeVerification::verify( $receiver = 'user@example.com', $purpose = 'verify_email', $user_id = 1, $code = '123456' );
3. Event
You can listen for the following events when they are triggered:
- When issued :
CodeIssuedEvent - When Verified :
CodeVerifiedEvent - When Revoked :
CodeRevokedEvent
4. Configuration
If you need, you can publish configuration file.
php artisan vendor:publish --tag=code-verification-config
You can change the configuration values through the config/code_verification.php file.
return [ 'code_length' => 6, // Length of the generated code 'expires_in' => 300, // Code expiration time (in seconds) 'max_attempts' => 3, // Maximum number of attempts ];
Uninstall Package
Rollback the specific migration
php artisan migrate:rollback --path=/vendor/codedive-io/laravel-code-verification/database/migration
Uninstall the package using Composer.
composer remove codedive-io/laravel-code-verification
Contribution
Bug reports, feature suggestions, and pull requests are welcome. You can contribute via the Github Repository.
LICENSE
This package is open-sourced software licensed under the MIT license.
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-29