Skip to content

TOTP verification returning always false #230

Open
@programarivm

Description

Description

Hi there,

I'm using the following sample script to simulate a user sign up.

<?php

// sign_up.php

require_once __DIR__ . '/../vendor/autoload.php';

use OTPHP\InternalClock;
use OTPHP\TOTP;

$secret = 'JDDK4U6G3BJLEZ7Y';

$otp = TOTP::createFromSecret($secret, new InternalClock());
$otp->setPeriod(20);
$otp->setDigest('sha512');
$otp->setDigits(8);
$otp->setEpoch(100);
$otp->setLabel('alice@foo.bar');
$otp->setIssuer('Example');

$grCodeUri = $otp->getQrCodeUri(
    'https://api.qrserver.com/v1/create-qr-code/?data=[DATA]&size=300x300&ecc=M',
    '[DATA]'
);


echo $grCodeUri . PHP_EOL;

So far so good. The generated $grCodeUri is then scanned with Authy which seems to be working okay in that Authy is generating the TOTP codes. However, I can't manage to verify any of the codes by Authy if using the script below.

<?php

// sign_in.php

require_once __DIR__ . '/../vendor/autoload.php';

use OTPHP\InternalClock;
use OTPHP\TOTP;

$secret = 'JDDK4U6G3BJLEZ7Y';

$otp = TOTP::createFromSecret($secret, new InternalClock());

$verified = $otp->verify($argv[1], null, 5);

echo (int) $verified . PHP_EOL;

Could you please elaborate on this example?

Thanks for the help,

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions