PHPackages                             mahdialikhani/otp-authenticator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. mahdialikhani/otp-authenticator

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

mahdialikhani/otp-authenticator
===============================

This package assists with authenticating users using OTP (One-Time Password) method.

0.0.2(3y ago)310MITPHPPHP ^8.0

Since Feb 6Pushed 3y ago1 watchersCompare

[ Source](https://github.com/mahdi-alikhani/otp-authenticator)[ Packagist](https://packagist.org/packages/mahdialikhani/otp-authenticator)[ RSS](/packages/mahdialikhani-otp-authenticator/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (1)DependenciesVersions (3)Used By (0)

[![Social Card of Laravel Media Library](./art/socialcard.png)](./art/socialcard.png)

OTP Authenticator
=================

[](#otp-authenticator)

[![GitHub release (latest SemVer)](https://camo.githubusercontent.com/7d63975ce3a16b3ea4f7005872ba4467021f7a8cbea5b5c0c979cce4e6eb806e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6d616864692d616c696b68616e692f6f74702d61757468656e74696361746f723f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/7d63975ce3a16b3ea4f7005872ba4467021f7a8cbea5b5c0c979cce4e6eb806e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6d616864692d616c696b68616e692f6f74702d61757468656e74696361746f723f7374796c653d666c61742d737175617265)[![Packagist Downloads](https://camo.githubusercontent.com/1679805ef565f813ff5379c87825715b2170c496e6207a9afcbf30acb63dd38b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d61686469616c696b68616e692f6f74702d61757468656e74696361746f72)](https://camo.githubusercontent.com/1679805ef565f813ff5379c87825715b2170c496e6207a9afcbf30acb63dd38b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d61686469616c696b68616e692f6f74702d61757468656e74696361746f72)

The **OTP Authenticator** package provides a simple and efficient solution for ensuring the security of your users' accounts. With the OTP (One-Time Password) method, users can securely log in to their accounts without the fear of their credentials being compromised. The package is easy to install and integrates seamlessly with your Laravel application, making it a hassle-free experience for developers.

Installation
============

[](#installation)

### Requirements

[](#requirements)

- **PHP 8.0+**
- **Laravel 8+**

You can install the package via composer:

```
composer require mahdialikhani/otp-authenticator
```

and add the **OTPAuthenticatorServiceProvider** service provider to **config/app.php**

and then run:

```
php artisan vendor:publish --tag=otpauthenticator

php artisan otp:install
```

Our default support includes two text message service provider, Ghasedak and Kavenegar, with plans to expand our support to additional services. To use any of these services, simply follow the instructions provided.

Kavenegar:
----------

[](#kavenegar)

To utilize the Kavenegar service, first follow the installation instructions for the Kavenegar package as outlined in the service provider's official documentation. Then, specify the SMS sender number in the **config/otpauthenticator.php** file.

```
'kavenegar' => [
    'line_number' => ''
]
```

and then:

You can edit the toSms function in the **\\App\\Notifications\\VerificationNotification** class as follows:

```
return (new KavenegarMessage)
            ->to('09301111111')
            ->message('Hi dear, your verification code is:123456');
```

and done!

Ghasedak:
---------

[](#ghasedak)

To utilize the ghasedak service, first follow the installation instructions for the ghasedak package provided in the official service provider's documentation. If you opt to use a pre-made text message template from the Ghasedak service, indicate the name of your selected template in the **config/otpauthenticator.php** file.

```
'ghasedak' => [
    'template_name' => ''
]
```

and then:

You can edit the toSms function in the **\\App\\Notifications\\VerificationNotification** class as follows:

```
return (new GhasedakMessage)
            ->to('09301111111')
            ->message('123456');
```

and done!

You can use the Laravel documentation to use the [vonage](https://laravel.com/docs/9.x/notifications#sms-notifications) service or create a personalized service by following these steps:

- Create a custom class in **\\App\\Notifications\\Messages** that implements the **Messageable** interface.
- Define the send method for sending your text message.
- Use this class in the **\\App\\Notifications\\VerificationNotification** file, similar to other services.

**To conveniently access the recipient and message text, extend your message class from the "SimpleMessage" class.**

for example:

```
