class EtFakeCcd::Validator::OtpValidator

Attributes

otp[RW]

Public Class Methods

new(secret: ::EtFakeCcd.config.microservice_secret, **args) click to toggle source
Calls superclass method
# File lib/et_fake_ccd/validator/otp_validator.rb, line 5
def initialize(secret: ::EtFakeCcd.config.microservice_secret, **args)
  self.otp = ROTP::TOTP.new(secret)
  super
end

Public Instance Methods

validate_each(record, attribute, value) click to toggle source
# File lib/et_fake_ccd/validator/otp_validator.rb, line 10
def validate_each(record, attribute, value)
  record.errors.add :one_time_password, 'Invalid oneTimePassword' unless otp.verify(value, drift_behind: 15)
end