public function verify($otp)
 {
     /** @var SmsVerificationState|null $state */
     $state = $this->session->get($this->sessionKey);
     if (!$state) {
         return OtpVerification::matchExpired();
     }
     $verification = $state->verify($otp);
     if ($verification->wasSuccessful()) {
         $this->session->remove($this->sessionKey);
     }
     return $verification;
 }
예제 #2
0
 public function verify($userOtp)
 {
     if (!is_string($userOtp)) {
         throw InvalidArgumentException::invalidType('string', 'userOtp', $userOtp);
     }
     if (strtoupper($userOtp) !== strtoupper($this->otp)) {
         return OtpVerification::noMatch();
     }
     $expiryTime = clone $this->issuedAt;
     $expiryTime->add($this->expiryInterval);
     if ($expiryTime <= DateTime::now()) {
         return OtpVerification::matchExpired();
     }
     return OtpVerification::foundMatch($this->phoneNumber);
 }