lib2fa.inc.php 1.1 KB

1234567891011121314151617181920212223242526272829
  1. <?php
  2. // https://github.com/Spomky-Labs/otphp/blob/11.2.x/doc/index.md
  3. // https://www.youtube.com/watch?v=e-1Yh8iH8jk&ab_channel=Boris%28%27PrimFX%27%29
  4. // Documentation disponible ici : https://chillerlan.github.io/php-qrcode/
  5. // Format de création des code QR pour 2FA :
  6. // $data = 'otpauth://totp/liberations:user@gmail.com?secret=B3JX4VCVJDVNXNZ5&issuer=https://liberations.magikweb.ca/';
  7. // Get the token
  8. // -------------
  9. function getUser2faSecret() {
  10. // Random secret will be generated from this.
  11. $otp = OTPHP\TOTP::generate();
  12. //TODO Corriger l'adresse courriel
  13. //$otp->setLabel('alice@google.com');
  14. //echo "The OTP secret is: {$secret}<br>\n";
  15. //echo "The current OTP is: {$otp->now()}<br>\n";
  16. return $otp->getSecret(); // À inscrire dans la base de données
  17. }
  18. // Check the token
  19. // ---------------
  20. function check2fa($secret, $input) {
  21. $otp = OTPHP\TOTP::createFromSecret($secret); // create TOTP object from the secret.
  22. //TODO Corriger l'adresse courriel
  23. //$otp->setLabel('alice@google.com');
  24. return $otp->verify($input);
  25. }