Class: TuwienLogon::Authentication::Authentication

Inherits:
Object
  • Object
show all
Defined in:
lib/tuwien_logon/authentication.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_id, client_host_name, secret, tolerance = 0, timestamp = Time.now) ⇒ Authentication

Returns a new instance of Authentication.



18
19
20
21
22
23
24
# File 'lib/tuwien_logon/authentication.rb', line 18

def initialize(user_id, client_host_name, secret, tolerance=0, timestamp=Time.now)
  @user_id = user_id.to_s
  @client_host_name = client_host_name.downcase
  @secret= secret.to_s
  @timestamp = timestamp.to_i / 10
  @tolerance = tolerance
end

Instance Attribute Details

#client_host_nameObject

Returns the value of attribute client_host_name.



16
17
18
# File 'lib/tuwien_logon/authentication.rb', line 16

def client_host_name
  @client_host_name
end

#secretObject

Returns the value of attribute secret.



16
17
18
# File 'lib/tuwien_logon/authentication.rb', line 16

def secret
  @secret
end

#timestampObject

Returns the value of attribute timestamp.



16
17
18
# File 'lib/tuwien_logon/authentication.rb', line 16

def timestamp
  @timestamp
end

#toleranceObject

Returns the value of attribute tolerance.



16
17
18
# File 'lib/tuwien_logon/authentication.rb', line 16

def tolerance
  @tolerance
end

#user_idObject

Returns the value of attribute user_id.



16
17
18
# File 'lib/tuwien_logon/authentication.rb', line 16

def user_id
  @user_id
end

Instance Method Details

#skey(time_offset = 0) ⇒ Object



26
27
28
# File 'lib/tuwien_logon/authentication.rb', line 26

def skey(time_offset = 0)
  Digest::SHA1.hexdigest(user_id + (timestamp + time_offset).to_s + client_host_name + secret)
end

#valid?(skey_to_check) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
# File 'lib/tuwien_logon/authentication.rb', line 30

def valid?(skey_to_check)
  (-tolerance..tolerance).each do |time_offset|
    return true if skey(time_offset) == skey_to_check
  end
  false
end