Skip to content

Commit

Permalink
Bug fixes & improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
prasanth-j committed Aug 8, 2022
1 parent 7bd78ab commit a32c7cd
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ return [
/**
* The length of token.
*/
'digits' => env('OTPIFY_DIGITS', 6),
'digits' => 6,

/**
* The expiry time of token in minutes.
*/
'validity' => env('OTPIFY_VALIDITY', 15)
'validity' => 15
];
```

Expand Down
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@
],
"minimum-stability": "dev",
"require": {
"php": ">=7.4.0"
"php": "^8.0",
"illuminate/console": "^9.0",
"illuminate/database": "^9.0",
"illuminate/support": "^9.0",
"nesbot/carbon": "^2.35"
},
"require-dev": {
"illuminate/config": "^9.0"
},
"config": {
"optimize-autoloader": true,
Expand Down
4 changes: 2 additions & 2 deletions config/otpify.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
/**
* The length of token.
*/
'digits' => env('OTPIFY_DIGITS', 6),
'digits' => 6,

/**
* The expiry time of token in minutes.
*/
'validity' => env('OTPIFY_VALIDITY', 15)
'validity' => 15
];
4 changes: 4 additions & 0 deletions src/Facades/Otpify.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

use Illuminate\Support\Facades\Facade;

/**
* @method static array generate(string $identifier, int $userId = null, string $otpType = null, int $digits = null, int $validity = null)
* @method static array validate(string $identifier, string $token, string $otpType = null)
*/
class Otpify extends Facade
{
/**
Expand Down
23 changes: 14 additions & 9 deletions src/Otpify.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@ class Otpify
*/
public static function generate(string $identifier, int $userId = null, string $otpType = null, int $digits = null, int $validity = null)
{
if ($digits === null) $digits = config('otpify.digits');
if ($validity === null) $validity = config('otpify.validity');
if ($digits === null) {
$digits = config('otpify.digits');
}

if ($validity === null) {
$validity = config('otpify.validity');
}

Otp::where([
['identifier', $identifier],
['otp_type', $otpType]
])->delete();

if (($digits >= 4) && ($digits <= 8)) {
if (($digits >= 4) && ($digits <= 12)) {
$token = rand(pow(10, $digits - 1), pow(10, $digits) - 1);

Otp::create([
Expand All @@ -38,13 +43,13 @@ public static function generate(string $identifier, int $userId = null, string $
'validity' => $validity,
'otp_type' => $otpType
]);
}

return [
'status' => 'success',
'token' => $token,
'message' => 'OTP genetated successfully'
];
return [
'status' => 'success',
'token' => $token,
'message' => 'OTP genetated successfully'
];
}
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/OtpifyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace PrasanthJ\Otpify;

use PrasanthJ\Otpify\Commands\CleanOtps;
use Illuminate\Support\ServiceProvider;
use PrasanthJ\Otpify\Commands\CleanOtps;
use PrasanthJ\Otpify\Otpify;

class OtpifyServiceProvider extends ServiceProvider
{
Expand All @@ -14,7 +15,7 @@ class OtpifyServiceProvider extends ServiceProvider
*/
public function register()
{
$this->app->bind('Otpify', \PrasanthJ\Otpify\Otpify::class);
$this->app->bind('Otpify', Otpify::class);
}

/**
Expand Down

0 comments on commit a32c7cd

Please sign in to comment.