Sha256: c727d5c75f24ae97cf27cbbdb928ca3d0af7b2bee8bc09740670e4f59efcb247

Contents?: true

Size: 578 Bytes

Versions: 5

Compression:

Stored size: 578 Bytes

Contents

# frozen_string_literal: true

module Masks
  module Credentials
    # Checks :factor2 for a valid one-time code.
    class OneTimeCode < Masks::Credential
      include Factor2

      private

      def param
        :one_time_code
      end

      def secret
        actor&.totp_secret
      end

      def verify(code)
        valid_code?(code, secret)
      end

      def valid_code?(code, secret)
        if code && secret
          actor.totp.verify(code)
        else
          false
        end
      rescue OpenSSL::HMACError
        false
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
masks-0.4.0 app/models/masks/credentials/one_time_code.rb
masks-0.3.2 app/models/masks/credentials/one_time_code.rb
masks-0.3.1 app/models/masks/credentials/one_time_code.rb
masks-0.3.0 app/models/masks/credentials/one_time_code.rb
masks-0.2.0 app/models/masks/credentials/one_time_code.rb