Sha256: dc6c9bc467164a55a2f95ff59a28b9b29ce3055ed02c753322cc5c26c2850a9b

Contents?: true

Size: 895 Bytes

Versions: 4

Compression:

Stored size: 895 Bytes

Contents

module ROTP
  class HOTP < OTP
    # Generates the OTP for the given count
    # @param [Integer] count counter
    # @returns [Integer] OTP
    def at(count)
      generate_otp(count)
    end

    # Verifies the OTP passed in against the current time OTP
    # @param [String/Integer] otp the OTP to check against
    # @param [Integer] counter the counter of the OTP
    def verify(otp, counter)
      otp == self.at(counter)
    end

    # Returns the provisioning URI for the OTP
    # This can then be encoded in a QR Code and used
    # to provision the Google Authenticator app
    # @param [String] name of the account
    # @param [Integer] initial_count starting counter value, defaults to 0
    # @return [String] provisioning uri
    def provisioning_uri(name, initial_count=0)
      "otpauth://hotp/#{URI.encode(name)}?secret=#{secret}&counter=#{initial_count}"
    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rotp-1.3.2 lib/rotp/hotp.rb
rotp-1.3.1 lib/rotp/hotp.rb
rotp-1.3.0 lib/rotp/hotp.rb
rotp-1.2.0 lib/rotp/hotp.rb