PHP code example of shiwildy / phptotp

1. Go to this page and download the library: Download shiwildy/phptotp 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/ */

    

shiwildy / phptotp example snippets




    iWildy\phptotp;

    // Setup phptotp instance
    $phptotp = new phptotp();
    
    // Generate Secret Key
    $secret = $phptotp->getSecret();
    echo "Secret Key: " . $secret . PHP_EOL;
    
    // Generate Current auth code
    $auth = $phptotp->getAuth($secret);
    echo  "Current Auth Code:" . $auth . PHP_EOL;
    
    // Verify Auth code with secret key
    $verify = $phptotp->verify($auth, $secret);
    if ($verify === true) {
        echo "Verify status: Correct" . PHP_EOL;
    } else {
        echo "Verify status: Incorrect" . PHP_EOL;
    }
    
    // Generate TOTP Link
    $qrcodelink = $phptotp->getQRCodeUrl("[email protected]", "MyApp", $secret);
    echo "Importable Link for QR: "  . $qrcodelink . PHP_EOL;