Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

42 lines (33 sloc) 0.839 kB
module Clearance
module PasswordStrategies
module BCrypt
require 'bcrypt'
extend ActiveSupport::Concern
def authenticated?(password)
if encrypted_password.present?
::BCrypt::Password.new(encrypted_password) == password
end
end
def password=(new_password)
@password = new_password
if new_password.present?
self.encrypted_password = encrypt(new_password)
end
end
private
def encrypt(password)
::BCrypt::Password.create(password, cost: cost)
end
def cost
if test_environment?
::BCrypt::Engine::MIN_COST
else
::BCrypt::Engine::DEFAULT_COST
end
end
def test_environment?
defined?(::Rails) && ::Rails.env.test?
end
end
end
end
Jump to Line
Something went wrong with that request. Please try again.