Skip to content

Commit e042632

Browse files
committed
fix: Cache Expiry Time
1 parent 3df39c7 commit e042632

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44

55
![GitHub License](https://img.shields.io/github/license/tzsk/otp?style=for-the-badge)
66
[![Latest Version on Packagist](https://img.shields.io/packagist/v/tzsk/otp.svg?style=for-the-badge&logo=composer)](https://packagist.org/packages/tzsk/otp)
7-
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/tzsk/otp/Tests?label=tests&style=for-the-badge&logo=github)](https://github.com/tzsk/otp/actions?query=workflow%3ATests+branch%3Amaster)
7+
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/tzsk/otp/run-tests.yml?branch=master&label=tests&style=for-the-badge&logo=github)](https://github.com/tzsk/otp/actions?query=workflow%3ATests+branch%3Amaster)
88
[![Total Downloads](https://img.shields.io/packagist/dt/tzsk/otp.svg?style=for-the-badge&logo=laravel)](https://packagist.org/packages/tzsk/otp)
99

10-
1110
This is a tool to create OTP with an expiry for PHP without using any Database. This is primarily a Laravel Package but it can be used outside of Laravel also.
1211

1312
## :package: Installation
@@ -27,6 +26,7 @@ php artisan otp:publish
2726
## :fire: Usage in Laravel
2827

2928
Import the facade class:
29+
3030
```php
3131
use Tzsk\Otp\Facades\Otp;
3232
```
@@ -90,6 +90,7 @@ Here, in the above example for matching the OTP we can see that the same config
9090
### :ocean: Helper usage
9191

9292
You can use the package with provided helper function as well
93+
9394
```php
9495
$otp = otp()->make($secret);
9596
$otp = otp()->digits(8)->expiry(20)->make($secret);
@@ -110,7 +111,7 @@ Install the package with composer the same way as above. Then just use it with t
110111
$manager = otp('./otp-tmp');
111112

112113
/**
113-
* Default properties -
114+
* Default properties -
114115
* $digits -> 4
115116
* $expiry -> 10 min
116117
*/
@@ -141,7 +142,7 @@ Also, keep in mind that while matching the OTP keep the digit & expiry config sa
141142

142143
## :microscope: Testing
143144

144-
``` bash
145+
```bash
145146
composer test
146147
```
147148

@@ -159,8 +160,8 @@ Please review [our security policy](../../security/policy) on how to report secu
159160

160161
## :crown: Credits
161162

162-
- [Kazi Ahmed](https://github.com/tzsk)
163-
- [All Contributors](../../contributors)
163+
- [Kazi Ahmed](https://github.com/tzsk)
164+
- [All Contributors](../../contributors)
164165

165166
## :policeman: License
166167

src/Otp.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public function digits($digits): self
5050
public function generate($key): string
5151
{
5252
$secret = sha1(uniqid());
53-
$ttl = DateInterval::createFromDateString("{$this->getFreshTime()} seconds");
53+
$expiry = $this->expiry;
54+
$ttl = DateInterval::createFromDateString("{$expiry} seconds");
5455
$this->store->put($this->keyFor($key), $secret, $ttl);
5556

5657
return $this->calculate($secret);

0 commit comments

Comments
 (0)