PHP code example of cloudrepublic / shield-totp-mfa

1. Go to this page and download the library: Download cloudrepublic/shield-totp-mfa 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/ */

    

cloudrepublic / shield-totp-mfa example snippets


   public array $psr4 = [
       APP_NAMESPACE => APPPATH,
       'TotpMfa'     => APPPATH . 'ThirdParty/TotpMfa/src',
   ];
   

   public array $actions = [
       'register' => \TotpMfa\Authentication\Actions\TotpActivator::class, // optional
       'login'    => \TotpMfa\Authentication\Actions\TotpMfa::class,
   ];
   

public bool $forceEnrollmentOnNextLogin = true;

   public array $aliases = [
       // ... your existing aliases
       'totp-fresh' => \TotpMfa\Filters\RequireFreshTotp::class,
   ];
   

   $routes->group('admin/billing', ['filter' => ['session', 'totp-fresh']], static function ($routes) {
       $routes->get('stripe-settings', 'Admin\BillingController::index');
       $routes->post('stripe-settings', 'Admin\BillingController::update');
   });
   

public bool $stepUpRequiresEnrollment = true;
public string $stepUpEnrollRouteName  = 'totp-settings-enroll'; // or
                                        // 'mfa-settings-totp-enroll'
                                        // if using shield-mfa-dispatcher

public array $proxyIPs = [
    '10.0.1.200'     => 'X-Forwarded-For', // your actual proxy's IP
    '192.168.5.0/24' => 'X-Forwarded-For', // or a whole trusted subnet
];

public array $views = [
    'totp_mfa_verify' => 'App\Views\auth\my_totp_verify',
    // any keys you don't list keep using this package's default
];

   php spark totp-mfa:setup
   

   php spark key:generate
   

tests/TotpMfa/
  Libraries/Base32Test.php            <- pure codec round-trip, no DB/HTTP
  Libraries/TotpTest.php               <- self-consistency + official RFC 6238 vectors
  Libraries/TotpIdentityStoreTest.php  <- enrollment/confirm/disable, needs DB
  Authentication/Actions/TotpMfaTest.php       <- login verify, remember-device, forced enrollment
  Authentication/Actions/TotpActivatorTest.php <- registration-time QR/confirm/skip
  Filters/RequireFreshTotpTest.php      <- step-up challenge freshness logic
  LogoutTest.php                        <- sanity check, not a Shield logout re-test
sql
SELECT * FROM auth_remembered_devices WHERE user_id = <id>;