Class: TuwienLogon::Authentication::Authentication
- Inherits:
-
Object
- Object
- TuwienLogon::Authentication::Authentication
- Defined in:
- lib/tuwien_logon/authentication.rb
Instance Attribute Summary collapse
-
#client_host_name ⇒ Object
Returns the value of attribute client_host_name.
-
#secret ⇒ Object
Returns the value of attribute secret.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#tolerance ⇒ Object
Returns the value of attribute tolerance.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Instance Method Summary collapse
-
#initialize(user_id, client_host_name, secret, tolerance = 0, timestamp = Time.now) ⇒ Authentication
constructor
A new instance of Authentication.
- #skey(time_offset = 0) ⇒ Object
- #valid?(skey_to_check) ⇒ Boolean
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, =Time.now) @user_id = user_id.to_s @client_host_name = client_host_name.downcase @secret= secret.to_s @timestamp = .to_i / 10 @tolerance = tolerance end |
Instance Attribute Details
#client_host_name ⇒ Object
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 |
#secret ⇒ Object
Returns the value of attribute secret.
16 17 18 |
# File 'lib/tuwien_logon/authentication.rb', line 16 def secret @secret end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
16 17 18 |
# File 'lib/tuwien_logon/authentication.rb', line 16 def @timestamp end |
#tolerance ⇒ Object
Returns the value of attribute tolerance.
16 17 18 |
# File 'lib/tuwien_logon/authentication.rb', line 16 def tolerance @tolerance end |
#user_id ⇒ Object
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 + ( + time_offset).to_s + client_host_name + secret) end |
#valid?(skey_to_check) ⇒ 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 |