user11481923
user11481923

Reputation:

What is the problem in this code Authy PHP?

I created an authenticator using "authy" with php, but the verification in case of wrong otp does not work.

Code:

include('config/otp-authy/vendor/autoload.php');

$authy_api = new Authy\AuthyApi('HIDDEN');          
$otp = $_POST['otp'];               
$verification = $authy_api->verifyToken('HIDDEN', ''.$otp.'');

if ($verification->ok()) {
    $_SESSION['HIDDEn'] = $row['userId'];
     header("Location: home.php");                  
} else {
    $error_otp = "Il codice OTP è errato!";
}

ERROR:

PHP Fatal error: Uncaught exception 'Authy\AuthyFormatException' with message 'Invalid Token. Unexpected length.' in /var/www/HIDDEN/config/otp- authy/lib/Authy/AuthyApi.php:323\nStack trace:\n#0 /var/www/HIDDEN/config/otp-authy/lib/Authy/AuthyApi.php(105): Authy\AuthyApi->__validateVerify('HIDDEN', 'HIDDEN')\n#1 /var/www/HIDDEN/index.php(54): Authy\AuthyApi->verifyToken('HIDDEN', '222')\n#2 {main}\n thrown in /var/www/HIDDEN/config/otp- authy/lib/Authy/AuthyApi.php on line 323, referer: https://HIDDEN/index.php

Upvotes: 1

Views: 188

Answers (1)

user11481923
user11481923

Reputation:

It works when you change:

verifyToken('HIDDEN', ''.$otp.'')

To:

verifyToken('HIDDEN', $otp)

Upvotes: 1

Related Questions