teckwei1993/laravel-otp

Cache expires too early

Opened this issue · 0 comments

I'm using the latest Laravel release (10.45.1) and the latests version of this package.

I received complaints from my users that the otp code is not valid even when they enter the exact code that they received.
After investigating, I found that the otp request data can't be found in the cache after 45 seconds. Without data, the code is invalid.

By default, the cache is valid for 15 minutes but when the otp data are stored in the cache, the data are only stored for 45 seconds because app()->version() >= "5.8" is not true anymore.

private function writeData(string $key, $value)
    {
        $expires = $this->expires;
        if(app()->version() >= "5.8"){
            $expires *= 60;
        }
        return Cache::put($this->prefix.$key, $value, $expires*3);
    }

This was introduced 3 years ago in version 1.0.5 to support older version of Laravel.
I think that now, it is safe to remove support for those version and come back to

private function writeData(string $key, $value)
    {
        return Cache::put($this->prefix.$key, $value, $this->expires*60*3);
    }

or use the opposite logic to support older version ...