Skip to content

Commit

Permalink
Fix composer installation bug
Browse files Browse the repository at this point in the history
v1.1.2 ed4
  • Loading branch information
imseyed committed Aug 6, 2024
1 parent c4aeceb commit fe52a00
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "MIT",
"autoload": {
"psr-4": {
"Imseyed\\Auth2fa\\": "src/"
"imseyed\\": "src/"
}
},
"authors": [
Expand Down
5 changes: 2 additions & 3 deletions examples/hotp.example.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php
use imseyed\Auth2FA\Auth2FA;
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/../vendor/autoload.php';

//$secret = Auth2FA::generate_secret();
// OR
$secret = 'OVZ7 JFIP IXE4 RTCE GCQE G2JN UY2Q PVD6'; // Replace your secret code

$hotp = Auth2FA::HOTP($secret, 1);
$hotp = imseyed\Auth2FA::HOTP($secret, 1);


echo "Code: $hotp".PHP_EOL;
7 changes: 3 additions & 4 deletions examples/totp.example.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php
use imseyed\Auth2FA\Auth2FA;
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/../vendor/autoload.php';

//$secret = Auth2FA::generate_secret();
// OR
$secret = 'OVZ7 JFIP IXE4 RTCE GCQE G2JN UY2Q PVD6'; // Replace your secret code

$totp = Auth2FA::TOTP($secret, 30);
$expirationTime = Auth2FA::expire_time(30);
$totp = imseyed\Auth2FA::TOTP($secret, 30);
$expirationTime = imseyed\Auth2FA::expire_time(30);


echo "Code: $totp".PHP_EOL;
Expand Down
14 changes: 10 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,26 @@ This PHP library provides functionality for generating Time-based One Time Passw

## Usage


### Install via composer:

```
composer require imseyed/auth2fa
```
### TOTP Generation

The `Auth2FA::TOTP` method generates a **Time-based One Time Password** using the provided secret key and optional time slice.
[totp.example.php](examples/totp.example.php)
```php
$totp = Auth2FA::TOTP($secret, $timeSlice);
$totp = imseyed\Auth2FA::TOTP($secret, $timeSlice);
/*
$totp is a OPT code like: 458905
*/
```

If you want show expiration time of TOTP code must use `Auth2FA::expire_time`. that method return a number Unix timestamp.
```php
$expirationTime = Auth2FA::expire_time($timeSlice);
$expirationTime = imseyed\Auth2FA::expire_time($timeSlice);
echo "Expire on ".date("H:i:s", $expirationTime)." (".($expirationTime - time())."s remind)";
/*
$expirationTime is a unix timestamp like: 1722929683
Expand All @@ -36,7 +42,7 @@ echo "Expire on ".date("H:i:s", $expirationTime)." (".($expirationTime - time())
The `Auth2FA::HOTP` method generates an **HMAC-based One Time Password** using the provided secret key and counter value.
[hotp.example.php](examples/hotp.example.php)
```php
$code = Auth2FA::HOTP($secret, $counter);
$code = imseyed\Auth2FA::HOTP($secret, $counter);
/*
$code is string like: 111222
*/
Expand All @@ -48,7 +54,7 @@ The `Auth2FA::generateSecret` method generates a **random secret key** of the sp

```php
$length = 16; // Secret key lenght
$secret = Auth2FA::generate_secret($length);
$secret = \imseyed\Auth2FA::generate_secret($length);
/*
$secret is string like: OVZ7JFIPIXE4RTCE
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Auth2FA.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace imseyed\Auth2FA;
namespace imseyed;

class Auth2FA{
/**
Expand Down

0 comments on commit fe52a00

Please sign in to comment.