Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/masoudghadimi/twofactorauth

Laravel Two-Factor Authenticated For Laravel/Ui
https://github.com/masoudghadimi/twofactorauth

laravel-two-factor-auth laravel8 two-factor-authentication twofactorauth

Last synced: about 2 months ago
JSON representation

Laravel Two-Factor Authenticated For Laravel/Ui

Awesome Lists containing this project

README

        

twoFactorAuth


Laravel Two-Factor Authenticated For Laravel/Ui

This package is being developed and debugged

Install

1) Install package - using composer

`composer require masoudghadimi/two-factor-auth`

2) Publish configuration file

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

3) Migration

`php artisan migrate`

4) Update User model (app/Models/User)

```php

protected $fillable = [
'name',
'email',
'password',
'phone_number',
'two_factor_type'
];

```

5) Add this codes to the User model (app/Models/User)

```php

public function verifyCodes()
{
return $this->hasMany(VerifyCode::class);
}

```

6) Add this codes to the LoginController (app/Http/Auth/LoginController)

```php
use TwoFactorAuthenticate;

protected function authenticated(Request $request, $user)
{
return $this->loggedIn($request , $user);
}

```

Configuration

Open configuration file - config/twoFactor.php

- Detect the channel
- change the route prefix
- Change the expiration time
- Change the number of digits in the code

Next step

Create channel file and then put it in the config file (notificationsChannels)

For example :

create SmsVerifyCodeChannel.php in app/channels then enter your desired code as below

```php

class SmsVerifyCodeChannel
{
public function send($notifiable, Notification $notification)
{
if (! method_exists($notification , 'toSendVerifyCode')) {
throw new \Exception('toSendVerifyCode not found');
}

$data = $notification->toSendVerifyCode($notifiable);

$message = $data['message'];
$phone = $data['number'];

try{
$lineNumber = 1111111;
$api = new \Ghasedak\GhasedakApi('token');
$api->SendSimple($phone, $message, $lineNumber);
}
catch(ApiException $e){
echo $e->errorMessage();
}
catch(HttpException $e){
echo $e->errorMessage();
}
}
}

```

Next, enter the config/twofactor.php file and in the notificationsChannels section, enter the created channel as follows:

```php

'notificationsChannels' => \App\channels\SmsVerifyCodeChannel::class,

```

Last step

Go to the link below :

`
localhost:8000/home/security
`

Good luck