Migration legacy database hack - stopped working? #1858

Closed
shanlalit opened this Issue May 17, 2012 · 8 comments

Comments

Projects
None yet
2 participants

I'm using Rails 3.1.4 on REE 1.8.7, updated from 2.0.4 to 2.1, now the legacy hack has stopped working.

In 2.0.4 it was working fine, in 2.1 it returning 401, do I need change anything?

Owner

josevalim commented May 17, 2012

What is the legacy database hack?

Owner

josevalim commented May 17, 2012

Btw, were you running on Devise 2.0.4 without deprecations warnings?

I'm following this How To: Migration legacy database to migrate from clearance to Devise, the only change is sha1 instead of MD5. Yes it is working fine with 2.0.4 without deprecations warnings.

Owner

josevalim commented May 17, 2012

Looking at the wiki, i can't see any reason for that to stop working. Are
you getting an exception or it simply doesn't work anymore?

It doesn't work. I'm using pry for debugging and tried to binding.pry inside

def valid_password_with_legacy?(password)
  binding.pry
.
.
end

But it's not called during authentication process.

Owner

josevalim commented May 17, 2012

I have updated the gist to use DatabaseAuthenticatable.class_eval, can you
confirm if it works now? Also, can you confirm if the file is being loaded
in the first place?

Thanks Josevalim,

Issue is resolved. class_eval helped in debugging the issue.

My mistake I enabled config.pepper which triggered failed logins, and then enable encryptable which stooped executing this legacy support code.

Please accept my apologies for taking your valuable time, and thank you very much for helping me out.

Owner

josevalim commented May 18, 2012

@shanlalit now that you got it working, i would like to propose a better solution. Instead of using alias_method_chain, why don't you simply override it in your model and call super instead?

    class User
      def valid_password_with_legacy?(password)
        if self.legacy_password_hash.present?
          if ::Digest::MD5.hexdigest(password).upcase == self.legacy_password_hash
            self.password = password
            self.legacy_password_hash = nil
            self.save!
            true
          else
            false
          end
        else
          super
        end
      end

      def reset_password!(*args)
        self.legacy_password_hash = nil
        super
      end
    end

Can you try a solution along these lines and update the wiki if it works for you? Thanks! (closing this)

josevalim closed this May 18, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment