{"id":30108189,"url":"https://github.com/bitxpilot/laravel-otp-validate","last_synced_at":"2025-08-10T02:08:14.479Z","repository":{"id":90014349,"uuid":"605517996","full_name":"bitXpilot/laravel-otp-validate","owner":"bitXpilot","description":"OTP Validate Package in Laravel","archived":false,"fork":false,"pushed_at":"2023-02-27T21:28:27.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-23T21:09:46.851Z","etag":null,"topics":["email","laravel","otp","otp-validation","php","resend","security-code","sms"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bitXpilot.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-02-23T10:25:47.000Z","updated_at":"2023-02-23T10:44:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"3b6988df-827b-4a0d-9d60-94a4a7ecde31","html_url":"https://github.com/bitXpilot/laravel-otp-validate","commit_stats":null,"previous_names":["mickeystar29/laravel-otp-validate","jackeystar0209/laravel-otp-validate","gitdevstar/laravel-otp-validate","devstar0209/laravel-otp-validate","bitxpilot/laravel-otp-validate"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/bitXpilot/laravel-otp-validate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitXpilot%2Flaravel-otp-validate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitXpilot%2Flaravel-otp-validate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitXpilot%2Flaravel-otp-validate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitXpilot%2Flaravel-otp-validate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitXpilot","download_url":"https://codeload.github.com/bitXpilot/laravel-otp-validate/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitXpilot%2Flaravel-otp-validate/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269663702,"owners_count":24455828,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["email","laravel","otp","otp-validation","php","resend","security-code","sms"],"created_at":"2025-08-10T02:08:13.704Z","updated_at":"2025-08-10T02:08:14.463Z","avatar_url":"https://github.com/bitXpilot.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OTP Validate Package in Laravel\nThis package is for easy setup for OTP validation process. No hassle, just plug and play. Following the steps mentioned below and you will be able to get a fully working OTP Validation system. You can use this later for authentication or e-commerce production selling, order confirmation.\n\n\n[![Laravel 8|9](https://img.shields.io/badge/Laravel-7|8-orange.svg)](http://laravel.com)\n\n[![Latest Stable Version](https://img.shields.io/packagist/v/devstar/laravel-otp-validate.svg)](https://packagist.org/packages/devstar/laravel-otp-validate)\n\n[![Total Downloads](https://poser.pugx.org/devstar/laravel-otp-validate/downloads.png)](https://packagist.org/packages/devstar/laravel-otp-validate)\n\n[![License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://packagist.org/packages/devstar/laravel-otp-validate)\n\n## Requirements\n- [PHP \u003e= 7](http://php.net/)\n- [Laravel Framework](https://github.com/laravel/framework)\n\n## Installation\n\n### Install Package\nRequire this package with composer:\n```\ncomposer require devstar/laravel-otp-validate\n```\n### Add Service Provider \u0026 Facade\n\n#### For Laravel 5.5+\nOnce the package is added, the service provider and facade will be auto discovered.\n\n#### For Older versions of Laravel\nAdd the ServiceProvider to the providers array in `config/app.php`:\n```php\nFerdous\\OtpValidator\\OtpValidatorServiceProvider::class\n```\n\nAdd the Facade to the aliases array in `config/app.php`:\n```php\n'OtpValidator' =\u003e Ferdous\\OtpValidator\\OtpValidatorServiceProvider::class\n```\n\n## Publish Config\nOnce done, publish the config to your config folder using:\n```\nphp artisan vendor:publish --provider=\"Ferdous\\OtpValidator\\OtpValidatorServiceProvider\"\n```\nThis command will create a `config/otp.php` file.\n\n### Email Configs\nFrom the `.env` file the email configs are setup. No other changes required.\n\n### SMS Configs\nAs the SMS Gateways use different methods and also extra headers and params, you may need to update the sms configs in the `otp.php` file.\n\n## Migrate Database\nRun the following command to create the otps table.\n```\nphp artisan migrate\n```\nIt will create a otps table with the required columns.\n\n## Environment\nAdd the following Key-Value pair to the `.env` file in the Laravel application\n\n```\n# Basic OTP Configs\nOTP_SERVICE='enabled'\nOTP_TABLE_NAME='otps'\nOTP_TIMEOUT=120\nOTP_DIGIT=5\nOTP_RESEND_SERVICE='enabled'\nOTP_MAX_RETRY=2\nOTP_MAX_RESEND=1\n# Company and Service\nOTP_SERVICE_NAME=\nOTP_COMPANY_NAME=\n# OTP via Email / SMS\nOTP_SEND_BY_EMAIL=1\nOTP_SEND_BY_SMS=1\n# Email Configurations\nOTP_EMAIL_FROM=\nOTP_EMAIL_FROM_NAME=\nOTP_EMAIL_SUBJECT=\n# SMS Configurations\nOTP_SMSC_URL='https://sms'\nOTP_SMSC_METHOD=\nOTP_COUNTRY_CODE=\nOTP_SMSC_OVER_JSON=\nOTP_SMSC_PARAM_TO_NAME=\nOTP_SMSC_PARAM_MSG_NAME=\nOTP_SMSC_USER=\nOTP_SMSC_PASS=\nAWS_SNS_VERSION=\nAWS_SNS_KEY=\nAWS_SNS_SECRET=\nAWS_SNS_REGION=\n```\n\n## Definitions\nDefinition of the features in config are:\n\n- service : enable/disable OTP Service\n- timeout: timeout for OTP\n- digit: OTP Digit\n- resend-service: enable/disable resend Service\n- max-retry: max retry for a single request\n- max-resend: max resend for a single request\n- service-name: for which the service is used\n- company-name: for which company\n- send-by: there are 3 ways to share otp (Email/SMS/AWS SNS)\n- email: this key specifies the required information for email (e.g. from, name, subject etc.)\n- sms: configure with SMS gateway to send SMS. \n(Universal Configurator)\n\n## Defining Send By on Runtime\n\nThe config method can be used to set send-by [ SMS / Email / SNS ] at runtime.\n\n    config('otp.send-by.email', 1);\n    config('otp.send-by.sms', 0);\n\n## OTP Request Templates\nOnce the template files are published, open `resources/views/vendor/template-otp/`\n\n## Sample Controller\nRun the following command to create a controller.\n\n`php artisan make:controller OtpController`\n\nBelow is a sample for calling the OTP Validator in OtpController.\n\n```php\nnamespace App\\Http\\Controllers;\n\nuse Ferdous\\OtpValidator\\Object\\OtpRequestObject;\nuse Ferdous\\OtpValidator\\OtpValidator;\nuse Ferdous\\OtpValidator\\Object\\OtpValidateRequestObject;\n\nclass OtpController extends Controller\n{\n    /**\n     * @return array\n     */\n    public function requestForOtp()\n    {\n        return OtpValidator::requestOtp(\n            new OtpRequestObject('1432', 'buy-shirt', '01711084714', 'ferdousul.haque@gmail.com')\n        );\n    }\n\n    /**\n     * @param Request $request\n     * @return array\n     */\n    public function validateOtp(Request $request)\n    {\n        $uniqId = $request-\u003einput('uniqueId');\n        $otp = $request-\u003einput('otp');\n        return OtpValidator::validateOtp(\n            new OtpValidateRequestObject($uniqId,$otp)\n        );\n    }\n\n    /**\n     * @param Request $request\n     * @return array\n     */\n    public function resendOtp(Request $request)\n    {\n        $uniqueId = $request-\u003einput('uniqueId');\n        return OtpValidator::resendOtp($uniqueId);\n    }\n\n}\n```\n\nAdd the following to the `routes/web.php` file.\n\n```\nRoute::get('/test/otp-request', 'OtpController@requestForOtp');\nRoute::get('/test/otp-validate', 'OtpController@validateOtp');\nRoute::get('/test/otp-resend', 'OtpController@resendOtp');\n```\n\n## Response/Error Descriptions\nThe below table describes the error codes generated in the response and their corresponding meanings.\n\n```json\n{\n  \"code\": 201,\n  \"message\": \"OTP Sent to the recipient\",\n  \"uniqueId\": 1432,\n  \"type\": \"buy-shirt\"\n}\n```\n\n#### Request OTP Response Codes\n\n| Code   |                Meanings\n|--------|------------------------------------------\n| 201    |  Successfully Generated OTP and shared.\n| 400    |  Bad request.\n| 501    |  Resend Service Disabled.\n| 503    |  Service Unavailable.\n\n#### OTP Validate Response Codes\n\n| Code   |                Meanings\n|--------|------------------------------------------\n| 200    |  Correct OTP.\n| 400    |  Invalid OTP.\n| 404    |  OTP Expired/Not Found.\n| 413    |  Max Retry Exceeded.\n\n## License\nMIT\n\n## Special Thanks\n- [Nahid Bin Azhar](https://github.com/nahid) For the Feedback.\n\n## Support\n- For any bugs, please help to create an issue.\n- For any problem installing or configurations, feel free to knock me.\n[ferdousul.haque@gmail.com](mailto:ferdousul.haque@gmail.com)\n\n## Featured Article\n- [How to create a laravel OTP/Security code verification for e-commerce website](https://medium.com/@ferdousul.haque/how-to-create-a-laravel-otp-security-code-verification-for-e-commerce-website-55de8161cfb8)\n\n## Example SMS Gateways Configuration\n\n### [Muthofun](https://www.muthofun.com/)\nIf you are trying to integrate one of most popular SMS gateway of Bangladesh, muthofun is a popular Bulk SMS Gateway in our country. Here is a sample configuration for the Muthofun SMS Gateway\n\n```php\n'smsc' =\u003e [\n    'url' =\u003e env('OTP_SMSC_URL'),\n    'method' =\u003e env('OTP_SMSC_METHOD', 'GET'),\n    'add_code' =\u003e env('OTP_COUNTRY_CODE',null),\n    'json' =\u003e env('OTP_SMSC_OVER_JSON',1),\n    'headers' =\u003e [],\n    'params' =\u003e [\n        'send_to_param_name' =\u003e env('OTP_SMSC_PARAM_TO_NAME','number'),\n        'msg_param_name' =\u003e env('OTP_SMSC_PARAM_MSG_NAME','msg'),\n        'others' =\u003e [\n            'user' =\u003e env('OTP_SMSC_USER'),\n            'password' =\u003e env('OTP_SMSC_PASS'),\n            'unicode' =\u003e 1\n        ],\n    ]\n];\n```\n\n.env file will be as the following\n\n```\nOTP_SMSC_URL='http://clients.muthofun.com:8901/esmsgw/sendsms.jsp?'\nOTP_SMSC_METHOD='GET'\nOTP_COUNTRY_CODE='88'\nOTP_SMSC_OVER_JSON=0\nOTP_SMSC_PARAM_TO_NAME='mobiles'\nOTP_SMSC_PARAM_MSG_NAME='sms'\nOTP_SMSC_USER='YourUserName'\nOTP_SMSC_PASS='YourPassWord'\n```\n\n### [Infobip](https://www.infobip.com/)\nExample for integrating with the infobip SMS platform, renowned SMS Gateway.\n\nusing GET method\n\n```php\n'smsc' =\u003e [\n    'url' =\u003e env('OTP_SMSC_URL'),\n    'method' =\u003e env('OTP_SMSC_METHOD', 'GET'),\n    'add_code' =\u003e env('OTP_COUNTRY_CODE',null),\n    'json' =\u003e env('OTP_SMSC_OVER_JSON',1),\n    'headers' =\u003e [],\n    'params' =\u003e [\n        'send_to_param_name' =\u003e env('OTP_SMSC_PARAM_TO_NAME','number'),\n        'msg_param_name' =\u003e env('OTP_SMSC_PARAM_MSG_NAME','msg'),\n        'others' =\u003e [\n            'username' =\u003e env('OTP_SMSC_USER'),\n            'password' =\u003e env('OTP_SMSC_PASS'),\n            'from' =\u003e 'InfoSMS',\n            'flash' =\u003e true\n        ],\n    ]\n];\n```\n\n.env file will be as the following\n\n```\nOTP_SMSC_URL='https://{baseUrl}/sms/1/text/query?'\nOTP_SMSC_METHOD='GET'\nOTP_COUNTRY_CODE='88'\nOTP_SMSC_OVER_JSON=0\nOTP_SMSC_PARAM_TO_NAME='to'\nOTP_SMSC_PARAM_MSG_NAME='text'\nOTP_SMSC_USER='YourUserName'\nOTP_SMSC_PASS='YourPassWord'\n```\n\n### [msg91](https://msg91.com)\nSample for integrating with the msg91 SMS gateway.\n\nusing GET method\n\n```php\n'smsc' =\u003e [\n        'url' =\u003e env('OTP_SMSC_URL'),\n        'method' =\u003e env('OTP_SMSC_METHOD', 'GET'),\n        'add_code' =\u003e env('OTP_COUNTRY_CODE',null),\n        'json' =\u003e env('OTP_SMSC_OVER_JSON',1),\n        'headers' =\u003e [],\n        'params' =\u003e [\n            'send_to_param_name' =\u003e env('OTP_SMSC_PARAM_TO_NAME','number'),\n            'msg_param_name' =\u003e env('OTP_SMSC_PARAM_MSG_NAME','msg'),\n            'others' =\u003e [\n                'authkey' =\u003e 'YourAuthKey',\n                'sender' =\u003e 'YourSenderId',\n                'route' =\u003e '1',\n                'country' =\u003e '88',\n            ],\n        ],\n        'wrapper' =\u003e 'sms',\n    ];\n```\n\n.env file will be as the following\n\n```\nOTP_SMSC_URL='https://control.msg91.com/api/v2/sendsms?'\nOTP_SMSC_METHOD='POST'\nOTP_COUNTRY_CODE='88'\nOTP_SMSC_OVER_JSON=1\nOTP_SMSC_PARAM_TO_NAME='to'\nOTP_SMSC_PARAM_MSG_NAME='text'\nOTP_SMSC_USER='YourUserName'\nOTP_SMSC_PASS='YourPassWord'\n```\n\n### [Using AWS Simple Notification Service (SNS)](https://aws.amazon.com/sns/)\nSample steps for integrating with the AWS SNS.\n\nCreate a IAM user with the appropriate policy permissions. Go to the IAM service and create your application’s user; be sure to capture its AWS Key and AWS Secret values and put this into your environment file. From there add the following policy to the user or its group.\n\n```\n{\n    \"Version\": \"2012-10-17\",\n    \"Statement\": [\n        {\n            \"Sid\": \"AllowSendingSMSMessages\",\n            \"Effect\": \"Allow\",\n            \"Action\": [\n                \"sns:Publish\",\n                \"sns:SetSMSAttributes\",\n                \"sns:CheckIfPhoneNumberIsOptedOut\"\n            ],\n            \"Resource\": [\n                \"*\"\n            ]\n        }\n    ]\n}\n```\n\nHere we set the ability to publish, set SMS attributes and check for opt-outs and apply this across a wildcard resource instead of a specific topic as we will be sending notifications directly to phone numbers and not an SNS topic.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitxpilot%2Flaravel-otp-validate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitxpilot%2Flaravel-otp-validate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitxpilot%2Flaravel-otp-validate/lists"}