Class: Rack::Bacoo::Credentials

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/bacoo/credentials.rb

Constant Summary collapse

WRONG_USER =
[SecureRandom.hex, SecureRandom.hex].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(password_cost, users) ⇒ Credentials

Returns a new instance of Credentials.



13
14
15
16
# File 'lib/rack/bacoo/credentials.rb', line 13

def initialize(password_cost, users)
  @password_cost = password_cost
  @users = users
end

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



11
12
13
# File 'lib/rack/bacoo/credentials.rb', line 11

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



11
12
13
# File 'lib/rack/bacoo/credentials.rb', line 11

def username
  @username
end

Instance Method Details

#basic_authenticated?(session) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/rack/bacoo/credentials.rb', line 18

def basic_authenticated?(session)
  @username = session.username
  @password = BCrypt::Password.create(session.password, cost: @password_cost)
  authenticated?(@username, @password)
end

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/rack/bacoo/credentials.rb', line 24

def cookie_authenticated?(session)
  @username = session.username
  @password = session.password
  authenticated?(@username, BCrypt::Password.new(@password))
end