PHP code example of joanfabregat / secure-token-generator

1. Go to this page and download the library: Download joanfabregat/secure-token-generator 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/ */

    

joanfabregat / secure-token-generator example snippets


use JoanFabregat\SecureTokenGenerator\SecureTokenGenerator;

// A simple alphanumeric token
$token = SecureTokenGenerator::generate(16);

// With all the options
$token = SecureTokenGenerator::generate(
    length: 32,
    allowDigits: true,        // 0-9
    allowSpecialChars: true,  // !"#$%&'()*+,-./ 
    allowUppercase: true,     // A-Z
    allowLowercase: true,     // a-z
);

// An integer token (e.g. 6-digit OTP)
$otp = SecureTokenGenerator::generateInt(6);
// $otp is an int between 100000 and 999999