@@ -16,10 +16,6 @@ A PHP library for RFC 4226 and RFC 6238.
1616composer require lorddashme/php-two-factor-auth
1717```
1818
19- ### Native Way
20-
21- - @TODO
22-
2319## Usage
2420
2521### HOTP
@@ -34,8 +30,12 @@ require __DIR__ . '/vendor/autoload.php';
3430use LordDashMe\TwoFactorAuth\RFC4226\HOTP;
3531use LordDashMe\TwoFactorAuth\Utility\Base32;
3632
37- $hotp = new HOTP(Base32::encode('P@ssw0rd!'));
33+ $secret = Base32::encode('P@ssw0rd!');
34+
35+ $hotp = new HOTP($secret);
36+
3837$hotp->setLength(6)
38+ ->setAlgorithm('sha1')
3939 ->prepare()
4040 ->generate();
4141
@@ -52,8 +52,12 @@ require __DIR__ . '/vendor/autoload.php';
5252use LordDashMe\TwoFactorAuth\RFC4226\HOTP;
5353use LordDashMe\TwoFactorAuth\Utility\Base32;
5454
55- $hotp = new HOTP(Base32::encode('P@ssw0rd!'));
55+ $secret = Base32::encode('P@ssw0rd!');
56+
57+ $hotp = new HOTP($secret);
58+
5659$hotp->setLength(6)
60+ ->setAlgorithm('sha1')
5761 ->prepare();
5862
5963echo $hotp->verify('444555'); // true
@@ -71,10 +75,15 @@ require __DIR__ . '/vendor/autoload.php';
7175use LordDashMe\TwoFactorAuth\RFC6238\TOTP;
7276use LordDashMe\TwoFactorAuth\Utility\Base32;
7377
74- $totp = new TOTP(Base32::encode('P@ssw0rd!'));
75- $totp->setTimeRemainingInSeconds(30)
78+ $secret = Base32::encode('P@ssw0rd!');
79+
80+ $totp = new TOTP($secret);
81+
82+ $totp->setTimeZone('Asia/Manila')
83+ ->setTimeRemainingInSeconds(30)
7684 ->setTimeAdjustments(10)
7785 ->setLength(6)
86+ ->setAlgorithm('sha1')
7887 ->prepare()
7988 ->generate();
8089
@@ -91,10 +100,15 @@ require __DIR__ . '/vendor/autoload.php';
91100use LordDashMe\TwoFactorAuth\RFC6238\TOTP;
92101use LordDashMe\TwoFactorAuth\Utility\Base32;
93102
94- $totp = new TOTP(Base32::encode('P@ssw0rd!'));
95- $totp->setTimeRemainingInSeconds(30)
103+ $secret = Base32::encode('P@ssw0rd!');
104+
105+ $totp = new TOTP($secret);
106+
107+ $totp->setTimeZone('Asia/Manila')
108+ ->setTimeRemainingInSeconds(30)
96109 ->setTimeAdjustments(10)
97110 ->setLength(6)
111+ ->setAlgorithm('sha1')
98112 ->prepare();
99113
100114echo $totp->verify('552344'); // true
@@ -113,15 +127,18 @@ use LordDashMe\TwoFactorAuth\Utility\Base32;
113127use LordDashMe\TwoFactorAuth\GoogleAuthenticator\BarcodeURL;
114128use LordDashMe\TwoFactorAuth\GoogleAuthenticator\TOTPFormat;
115129
116- $secret = Base32::encode('P@ssw0rd!', false );
130+ $secret = Base32::encode('P@ssw0rd!');
117131$accountUser = 'reyesjoshuaclifford@gmail.com';
118132$issuer = 'TwoFactorAuth';
119133$digits = 6;
120134$period = 30;
135+ $algorithm = 'sha1';
136+
137+ $format = new TOTPFormat($period);
138+
139+ $barcodeURL = new BarcodeURL($secret, $accountUser, $issuer, $format);
121140
122- $totpFormat = new TOTPFormat($period);
123- $barcodeURL = new BarcodeURL($secret, $accountUser, $issuer, $totpFormat);
124- $barcodeURL->setAlgorithm('SHA1')
141+ $barcodeURL->setAlgorithm($algorithm) // sha1 (Default), sha256, sha512
125142 ->setDigits($digits)
126143 ->build();
127144
0 commit comments