Sha256: 27f40d88170e5531eb2e1eec697c6c497a8220cd9bc44a01dd55be7c52ab2aa3

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

# Stuff the gem requireds
#
require 'active_support'
require 'active_record'
require 'openssl'
require 'rotp'
require 'google-qr'

# Stuff the gem is
#
GOOGLE_AUTHENTICATOR_RAILS_PATH = File.dirname(__FILE__) + "/google-authenticator-rails/"

[
  "version",

  "action_controller",
  "active_record",
  "session"
].each do |library|
   require GOOGLE_AUTHENTICATOR_RAILS_PATH + library
 end

 # Sets up some basic accessors for use with the ROTP module
#
module GoogleAuthenticatorRails
  # Drift is set to 6 because ROTP drift is not inclusive.  This allows a drift of 5 seconds.
  DRIFT = 6

  # How long a Session::Persistence cookie should last.
  @@time_until_expiration = 24.hours

  def self.generate_password(secret, iteration)
    ROTP::HOTP.new(secret).at(iteration)
  end

  def self.time_based_password(secret)
    ROTP::TOTP.new(secret).now
  end

  def self.valid?(code, secret)
    ROTP::TOTP.new(secret).verify_with_drift(code, DRIFT)
  end

  def self.generate_secret
    ROTP::Base32.random_base32
  end

  def self.time_until_expiration
    @@time_until_expiration
  end

  def self.time_until_expiration=(time_until_expiration)
    @@time_until_expiration = time_until_expiration
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
google-authenticator-rails-0.0.9 lib/google-authenticator-rails.rb
google-authenticator-rails-0.0.8 lib/google-authenticator-rails.rb
google-authenticator-rails-0.0.7 lib/google-authenticator-rails.rb