Class: Rack::Bacoo::Credentials
- Inherits:
-
Object
- Object
- Rack::Bacoo::Credentials
- Defined in:
- lib/rack/bacoo/credentials.rb
Constant Summary collapse
- WRONG_USER =
[SecureRandom.hex, SecureRandom.hex].freeze
Instance Attribute Summary collapse
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #basic_authenticated?(session) ⇒ Boolean
- #cookie_authenticated?(session) ⇒ Boolean
-
#initialize(password_cost, users) ⇒ Credentials
constructor
A new instance of Credentials.
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
#password ⇒ Object (readonly)
Returns the value of attribute password.
11 12 13 |
# File 'lib/rack/bacoo/credentials.rb', line 11 def password @password end |
#username ⇒ Object (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
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 |
#cookie_authenticated?(session) ⇒ Boolean
24 25 26 27 28 |
# File 'lib/rack/bacoo/credentials.rb', line 24 def (session) @username = session.username @password = session.password authenticated?(@username, BCrypt::Password.new(@password)) end |