views:

22

answers:

1

I am trying to convert my custom simple auth system in my rails app to use AuthLogic. I have managed to get everything working fairly easily, but now when I try to login it will not properly validate my credentials. The pertinent code is below:

# app/models/profile.rb
class Profile < ActiveRecord::Base
  acts_as_authentic do |c|
    c.transition_from_crypto_providers = Authlogic::CryptoProviders::Sha1,
    c.crypto_provider = Authlogic::CryptoProviders::Sha512
  end
end

I used to use this to hash my password on creation:

# app/models/profile.rb
def hash_password
  self.salt = ActiveSupport::SecureRandom.base64(8)
  self.hashed_password = Digest:SHA1.hexdigest(self.salt + @password)
end

I have already converted all the necessary table columns to be compatible with AuthLogic. Is there a way to log what AuthLogic is hashing the password as? What else could be wrong?

A: 

I solved my problem, I had to write a custom crypto_provider, looked like this for anyone who is curious:

class MyCryptoProvider
  # Turns your raw password into a Sha1 hash.
  def self.encrypt(*tokens)
    tokens = tokens.flatten
    tokens = tokens.reverse
    digest = Digest::SHA1.hexdigest([*tokens].join)
    digest
  end

  # Does the crypted password match the tokens? Uses the same tokens that were used to encrypt.
  def self.matches?(crypted, *tokens)
    encrypt(*tokens) == crypted
  end
end
trobrock