ActiveModel::SecurePassword::InstanceMethodsOnActivation (original) (raw)

Methods

N

Class Public methods

Source: show | on GitHub

def initialize(attribute, reset_token:) attr_reader attribute

define_method("#{attribute}=") do |unencrypted_password| if unencrypted_password.nil? instance_variable_set("@#{attribute}", nil) self.public_send("#{attribute}_digest=", nil) elsif !unencrypted_password.empty? instance_variable_set("@#{attribute}", unencrypted_password) cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST : BCrypt::Engine.cost self.public_send("#{attribute}_digest=", BCrypt::Password.create(unencrypted_password, cost: cost)) end end

attr_accessor :"#{attribute}_confirmation", :"#{attribute}_challenge"

define_method("authenticate_#{attribute}") do |unencrypted_password| attribute_digest = public_send("#{attribute}_digest") attribute_digest.present? && BCrypt::Password.new(attribute_digest).is_password?(unencrypted_password) && self end

define_method("#{attribute}_salt") do attribute_digest = public_send("#{attribute}_digest") attribute_digest.present? ? BCrypt::Password.new(attribute_digest).salt : nil end

alias_method :authenticate, :authenticate_password if attribute == :password

if reset_token

define_method("#{attribute}_reset_token") do
  generate_token_for(:"#{attribute}_reset")
end

end end