PHP Classes

File: tests/HOTPTest.php

Recommend this page to a friend!
  Packages of A. B. M. Mahmudul Hasan   OTP   tests/HOTPTest.php   Download  
File: tests/HOTPTest.php
Role: Example script
Content type: text/plain
Description: Example script
Class: OTP
Generate token to be verified during a time window
Author: By
Last change:
Date: 20 days ago
Size: 726 bytes
 

Contents

Class file image Download
<?php

use Infocyph\OTP\HOTP;

test('Dynamic generation', function () {
   
$secret = HOTP::generateSecret();
   
$counter = 346;
   
$hotp = new HOTP($secret);
   
$otp = $hotp->getOTP($counter);
   
expect($otp)->toBeString()
        ->
and($otp)->toHaveLength(6)
        ->
and(($hotp->verify($otp,$counter)))->toBeTrue();
});

test('Predefined generation', function () {
   
$secret = 'GFZKEJSFNDSEZGG7K4C3UEYRWDF76LL5HD4HT73SDD6AE5EVRRH4OYPKIITGRH3MI2JUFZQX2GJNG66FPEEJIHYFP736JVONA5M7J4A';
   
$counter = 5;
   
$hotp = new HOTP($secret);
   
$otp = $hotp->getOTP($counter);
   
expect($otp)->toBeString()
        ->
and($otp)->toHaveLength(6)->toBe('201774')
        ->
and(($hotp->verify($otp,$counter)))->toBeTrue();
});