diff --git a/README.md b/README.md index db3181a..0a8232b 100644 --- a/README.md +++ b/README.md @@ -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 ]; ``` diff --git a/composer.json b/composer.json index d062b6e..103b0e5 100644 --- a/composer.json +++ b/composer.json @@ -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, diff --git a/config/otpify.php b/config/otpify.php index 11ed888..3c1ceba 100644 --- a/config/otpify.php +++ b/config/otpify.php @@ -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 ]; diff --git a/src/Facades/Otpify.php b/src/Facades/Otpify.php index 3d4c893..167a8a0 100644 --- a/src/Facades/Otpify.php +++ b/src/Facades/Otpify.php @@ -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 { /** diff --git a/src/Otpify.php b/src/Otpify.php index e744326..50a427c 100644 --- a/src/Otpify.php +++ b/src/Otpify.php @@ -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([ @@ -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' + ]; + } } /** diff --git a/src/OtpifyServiceProvider.php b/src/OtpifyServiceProvider.php index f6fbb39..a42e8d3 100644 --- a/src/OtpifyServiceProvider.php +++ b/src/OtpifyServiceProvider.php @@ -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 { @@ -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); } /**