Module: Clearance::PasswordStrategies::BCrypt

Defined in:
lib/clearance/password_strategies/bcrypt.rb

Overview

Uses BCrypt to authenticate users and store encrypted passwords.

The BCrypt cost (the measure of how many key expansion iterations BCrypt will perform) is automatically set to the minimum allowed value when Rails is operating in the test environment and the default cost in all other envionments. This provides a speed boost in tests.

Instance Method Summary collapse

Instance Method Details

#authenticated?(password) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
# File 'lib/clearance/password_strategies/bcrypt.rb', line 12

def authenticated?(password)
  if encrypted_password.present?
    ::BCrypt::Password.new(encrypted_password) == password
  end
end

#password=(new_password) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/clearance/password_strategies/bcrypt.rb', line 18

def password=(new_password)
  @password = new_password

  if new_password.present?
    self.encrypted_password = encrypt(new_password)
  end
end