PHP code example of doge-dev / laravel-google-authenticator
1. Go to this page and download the library: Download doge-dev/laravel-google-authenticator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
doge-dev / laravel-google-authenticator example snippets
namespace App;
use DogeDev\GoogleAuthenticator\Traits\Verifies2FACode;
use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Jenssegers\Mongodb\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasApiTokens, Notifiable, Verifies2FACode;
...
$table->boolean('activated_2fa')->default(false); // you can index it if needed
$table->string('secret')->nullable();
$user->enable2FA();
/**
* The attributes that should be visible for arrays.
*
* @var array
*/
protected $visible = ['name', 'enabled_2fa', 'activated_2fa'];
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = ['enabled_2fa'];
$user->activated_2fa
$user->activate2FA($request->get('code'));
$user->verifyCode($request->get('code'));
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class SomeCustomRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'code' => '
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UpdateAccountDetails extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'code' => '
class User extends Model
{
...
/**
* Gets the name to be displayed in Google Authenticator
*
* @return string
*/
public function getNameForQRCode()
{
return env('APP_NAME') . "@" . $this->email;
}
}
config/app.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.