sanjabteam / verify
Verify users mobile number by one time password.
Installs: 2 537
Dependents: 0
Suggesters: 0
Security: 0
Stars: 36
Watchers: 2
Forks: 10
Open Issues: 1
Requires
- php: ^7.3|^8
- illuminate/support: ^6|^7|^8|^9|^10|^11
Requires (Dev)
- orchestra/testbench: 3.8.*|^4|^5.1|^7.4|^8.0.4|v9.0.0
- phpunit/phpunit: ^8.4|^9.0|^10.0|^11.0
README
Verify your user mobile/email with a one-time password.
Installation
You can install the package via composer:
composer require sanjabteam/verify
Publish config file using:
php artisan vendor:publish --provider=SanjabVerify\VerifyServiceProvider
Configuration
code
: Unique code generator configs.
resend_delay
: Resend delay between code sends in seconds.
expire_in
: Expire sent code after minutes.
max_attemps
: Max code check attempts.
max_resends
: Maximum resends in one hour.
per_session
: Maximum resends in one hour based on the user session. (Limitation: if user clear cookie)per_ip
: Maximum resends in one hour based on user IP. (Limitation: If two different user use one proxy)
Usage
Send code to the user
use Verify; use App\Helpers\SmsVerifyMethod; $result = Verify::request($request->input('mobile'), SmsVerifyMethod::class); if ($result['success'] == false) { // If user exceed limitation return redirect()->back()->with('error', $result['message']); // Show error message }
App\Helpers\SmsVerifyMethod
is your send method class and you need to create that like this.
namespace App\Helpers; use SanjabVerify\Contracts\VerifyMethod; class SmsVerifyMethod implements VerifyMethod { public function send(string $receiver, string $code) { // Send code to receiver if (send_sms($receiver, 'Your code is :'.$code) == 'success') { return true; // If code sent successfuly then return true } return false; // If send code failed return false } }
Verify
You can verify code with request validation.
$request->validate([ 'code' => 'required|sanjab_verify:mobile' ]);
mobile
is your receiver which in this case is mobile.
You can also verify it manually.
use Verify; $result = Verify::verify($request->input('mobile'), $request->input('code')); if ($result['success'] == false) { // Show error $result['message'] }
Note: You can verify a code just once. so if you need to check code in two different requests then you should use something like the session to handle that.
Contributing
Contributions are welcome!
- Fork the Project
- Clone your project (git clone https://github.com/your_username/verify.git)
- Create new branch (git checkout -b your_feature)
- Commit your Changes (git commit -m 'new feature')
- Push to the Branch (git push origin your_feature)
- Open a Pull Request
License
The MIT License (MIT). Please see License File for more information.