example.php 1006 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of the Sonata Project package.
  5. *
  6. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. include_once __DIR__.'/../src/FixedBitNotation.php';
  12. include_once __DIR__.'/../src/GoogleAuthenticator.php';
  13. include_once __DIR__.'/../src/GoogleQrUrl.php';
  14. $secret = 'XVQ2UIGO75XRUKJO';
  15. $code = '846474';
  16. $g = new \Sonata\GoogleAuthenticator\GoogleAuthenticator();
  17. echo 'Current Code is: ';
  18. echo $g->getCode($secret);
  19. echo "\n";
  20. echo "Check if $code is valid: ";
  21. if ($g->checkCode($secret, $code)) {
  22. echo "YES \n";
  23. } else {
  24. echo "NO \n";
  25. }
  26. $secret = $g->generateSecret();
  27. echo "Get a new Secret: $secret \n";
  28. echo "The QR Code for this secret (to scan with the Google Authenticator App: \n";
  29. echo \Sonata\GoogleAuthenticator\GoogleQrUrl::generate('chregu', $secret, 'GoogleAuthenticatorExample');
  30. echo "\n";