Module: CASino::ProcessorConcern::TwoFactorAuthenticators

Included in:
SecondFactorAuthenticationAcceptorProcessor, TwoFactorAuthenticatorActivatorProcessor, TwoFactorAuthenticatorDestroyerProcessor
Defined in:
app/processors/casino/processor_concern/two_factor_authenticators.rb

Defined Under Namespace

Classes: ValidationResult

Instance Method Summary collapse

Instance Method Details

#validate_one_time_password(otp, authenticator) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/processors/casino/processor_concern/two_factor_authenticators.rb', line 9

def validate_one_time_password(otp, authenticator)
  if authenticator.nil? || authenticator.expired?
    ValidationResult.new 'INVALID_AUTHENTICATOR', 'Authenticator does not exist or expired', :warn
  else
    totp = ROTP::TOTP.new(authenticator.secret)
    if totp.verify_with_drift(otp, CASino.config.two_factor_authenticator[:drift])
      ValidationResult.new
    else
      ValidationResult.new 'INVALID_OTP', 'One-time password not valid', :warn
    end
  end
end