masoudghadimi / two-factor-auth
This package is abandoned and no longer maintained.
No replacement package was suggested.
Two factor authenticated for laravel-ui
v1.0-beta.3
2021-04-09 11:06 UTC
Requires
- illuminate/support: ^8.0
This package is auto-updated.
Last update: 2021-07-07 12:37:00 UTC
README
Laravel Two-Factor Authenticated For Laravel/Ui
This package is being developed and debugged
Install
- Install package - using composer
composer require masoudghadimi/two-factor-auth
- Publish configuration file
php artisan vendor:publish --tag=twoFactor
- Migration
php artisan migrate
- Update User model (app/Models/User)
protected $fillable = [ 'name', 'email', 'password', 'phone_number', 'two_factor_type' ];
- Add this codes to the User model (app/Models/User)
public function verifyCodes() { return $this->hasMany(VerifyCode::class); }
- Add this codes to the LoginController (app/Http/Auth/LoginController)
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
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:
'notificationsChannels' => \App\channels\SmsVerifyCodeChannel::class,
Last step
Go to the link below :
localhost:8000/home/security