Ruby on rails 从清除密码存储迁移到authlogic

Ruby on rails 从清除密码存储迁移到authlogic,ruby-on-rails,ruby,passwords,authlogic,Ruby On Rails,Ruby,Passwords,Authlogic,我目前正在开发一个Rails应用程序,它可以存储清晰的密码(…)。因此,我将迁移到使用“标准”SHA512加密的Authlogic身份验证 我做的很好: #file /models/user.rb class User < ActiveRecord::Base acts_as_authentic { |c| c.transition_from_crypto_providers = [MyOwnNoCrypto, Authlogic::CryptoProviders::Sha5

我目前正在开发一个Rails应用程序,它可以存储清晰的密码(…)。因此,我将迁移到使用“标准”SHA512加密的Authlogic身份验证

我做的很好:

#file /models/user.rb
class User < ActiveRecord::Base

  acts_as_authentic { |c|
    c.transition_from_crypto_providers = [MyOwnNoCrypto, Authlogic::CryptoProviders::Sha512]
  } 
end

#file /lib/my_own_no_crypto.rb
class MyOwnNoCrypto
  def self.encrypt(*tokens)
    return tokens[0] # or tokens.join I guess
  end

  def self.matches?(crypted_password, *tokens)
    return crypted_password == tokens.join
  end
end
#文件/models/user.rb
类用户
这很好——而且效果很好——但我想知道是否有一种更性感的方式可以做到这一点,也许有一个Authlogic核心选项


谢谢

就我个人而言,我会编写一个迁移程序,将所有明文密码迁移到加密密码中。您可以在迁移中定义自己的基本模型,以允许良好的低级别访问。

我同意其中的一部分,即建议一次性转换,而不是使用AuthLogic的转换模型。在这种情况下,您希望尽快加密这些密码,而不是在用户下次登录时。不过,我可能会建议迁移,而不是执行Rake任务:

# in db/migrate/nnnnnnnn_encrypt_passwords.rb:

class EncryptPasswords < ActiveRecord::Migration
  def self.up
    add_column :users, :crypted_password
    User.each do |u|
      u.encrypt_password!
    end
    remove_column :users, :password
  end

  def self.down
    raise IrreversibleMigration.new('Cannot decrypt user passwords')
  end
end
#在db/migrate/nnnnnnnn_encrypt_passwords.rb中:
类EncryptPasswords
Wow!太好了!谢谢。