-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Verify OTP without marking it as used. #39
Conversation
src/Otp.php
Outdated
if($otp){ | ||
$now = Carbon::now(); | ||
$validity = $otp->created_at->addMinutes($otp->validity); | ||
|
||
if( $otp->valid && (strtotime($validity) >= strtotime($now))) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ($otp instanceof Model) {
$validity = $otp->created_at->addMinutes($otp->validity);
return Carbon::now()->lt($validity);
}
return false;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the suggestion. I have added a condition to check the "valid" property in the model, as it could still be invalid even if Carbon::now()->lt($validity);
returns true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dropped a few comments and suggested code change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couple more changes
Summary
Some application may only need to check the validity of the OTP before using it, so, this pull request introduces a new method isValid to the Otp class. The isValid method checks the existence and validity of an OTP (the same way you use) without marking it as used.
Benefits
Usage