コード例 #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;
 }
コード例 #2
0
 /**
  * @test
  * @group security
  * @dataProvider nonPositiveIntegers
  * @expectedException \Surfnet\StepupBundle\Exception\InvalidArgumentException
  *
  * @param mixed $length
  */
 public function it_cannot_generate_otp_strings_of_negative_or_non_integer_length($length)
 {
     OtpGenerator::generate($length);
 }