Example #1
0
 public GenerateOTPResponse GenerateOtp(GenerateOTPRequest generateOtpRequest)
 {
     if (!IsNullOrEmpty(generateOtpRequest?.UserId))
     {
         try
         {
             var movingFactor = _movingFactorAlgorithm.GetMovingFactor();
             var otp          = _otpAlgorithm.GenerateOTP(generateOtpRequest.UserId, _otpConfiguration.PrivateKey,
                                                          movingFactor,
                                                          _otpConfiguration.NumberOfDigitsInOTP);
             Console.WriteLine("Generation: OTP : {0} MovingFactor: {1}", otp, movingFactor);
             return(new GenerateOTPResponse
             {
                 UserId = generateOtpRequest.UserId,
                 OTP = otp
             });
         }
         catch (ArgumentOutOfRangeException exception)
         {
             return(new GenerateOTPResponse
             {
                 Error = _errorFactory.GetErrorForException(exception)
             });
         }
     }
     return(new GenerateOTPResponse
     {
         Error = _errorFactory.GetInvalidRequestError()
     });
 }
        public void ShouldGenerateAnOTPWithGivenNumberOfDigits(int numberOfDigits)
        {
            var generateOTP = _hmacBasedOTPAlgorithm.GenerateOTP("hdaska7232kls6", "alasnkasdhas7232", 10,
                                                                 numberOfDigits);

            Assert.That(generateOTP, Is.Not.Null);
            Assert.That(generateOTP.Length, Is.EqualTo(numberOfDigits));
        }