Skip to content

Instantly share code, notes, and snippets.

@yasu
Last active December 21, 2015 23:38
Show Gist options
  • Select an option

  • Save yasu/6383276 to your computer and use it in GitHub Desktop.

Select an option

Save yasu/6383276 to your computer and use it in GitHub Desktop.
Switching from Restful Authentication to Devise while upgrading Rails 2.3 to Rails 3.
# /config/initializers/devise_encryptor.rb
require "digest/sha1"
REST_AUTH_SITE_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
REST_AUTH_DIGEST_STRETCHES = 10
module Devise
module Encryptable
module Encryptors
module ModelClassMethods
def secure_digest(*args)
Digest::SHA1.hexdigest(args.flatten.join('--'))
end
def make_token
secure_digest(Time.now, (1..10).map{ rand.to_s })
end
end # class methods
class OldRestfulAuthentication < Base
extend ModelClassMethods
def self.salt(stretches)
if defined?(password_salt)
password_salt
else
make_token
end
end
def self.digest(password, stretches, salt, pepper)
digest = REST_AUTH_SITE_KEY
REST_AUTH_DIGEST_STRETCHES.times {
digest = secure_digest(digest, salt, password, REST_AUTH_SITE_KEY)
}
digest
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment