Ejemplo n.º 1
0
 /**
  * @param string $phoneNumber
  * @return string The generated OTP string.
  */
 public function requestNewOtp($phoneNumber)
 {
     if (!is_string($phoneNumber) || empty($phoneNumber)) {
         throw InvalidArgumentException::invalidType('string', 'phoneNumber', $phoneNumber);
     }
     if (count($this->otps) >= $this->maximumOtpRequests) {
         throw new TooManyChallengesRequestedException(sprintf('%d OTPs were requested, while only %d requests are allowed', count($this->otps) + 1, $this->maximumOtpRequests));
     }
     $this->otps = array_filter($this->otps, function (Otp $otp) use($phoneNumber) {
         return $otp->hasPhoneNumber($phoneNumber);
     });
     $otp = OtpGenerator::generate(8);
     $this->otps[] = Otp::create($otp, $phoneNumber, $this->expiryInterval);
     return $otp;
 }
Ejemplo n.º 2
0
 /**
  * @test
  * @group sms
  * @dataProvider non_strings
  * @param mixed $nonString
  */
 public function it_verifies_only_string_otps($nonString)
 {
     $this->setExpectedException('Surfnet\\StepupBundle\\Exception\\InvalidArgumentException', 'otpString');
     $otp = Otp::create($nonString, '123', new DateInterval('PT5M'));
     $otp->verify($nonString);
 }