Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3.1 从Desive迁移到omniauth(标识)_Ruby On Rails 3.1_Devise_Omniauth - Fatal编程技术网

Ruby on rails 3.1 从Desive迁移到omniauth(标识)

Ruby on rails 3.1 从Desive迁移到omniauth(标识),ruby-on-rails-3.1,devise,omniauth,Ruby On Rails 3.1,Devise,Omniauth,我正在考虑从Desive 1.4.7迁移到Omniauth 1.0(使用“身份”策略或gem),我的问题是在完成所有代码转换、视图等之后,旧密码(使用Desive创建的用户帐户)是否仍然在Omniauth下使用相同的密码 我做了一些研究,两人都在使用bcrypt,所以我猜“是的”,他们会像以前一样工作,用户不必创建新密码。还是我遗漏了一些重要的东西?我不认为你遗漏了任何重要的东西。两者都在使用bcrypt。令人惊叹的。 但这有关系吗?我想真的有关系 Desive完成您的身份验证过程w.r.t到一

我正在考虑从Desive 1.4.7迁移到Omniauth 1.0(使用“身份”策略或gem),我的问题是在完成所有代码转换、视图等之后,旧密码(使用Desive创建的用户帐户)是否仍然在Omniauth下使用相同的密码


我做了一些研究,两人都在使用bcrypt,所以我猜“是的”,他们会像以前一样工作,用户不必创建新密码。还是我遗漏了一些重要的东西?

我不认为你遗漏了任何重要的东西。两者都在使用
bcrypt
。令人惊叹的。 但这有关系吗?我想真的有关系

Desive完成您的身份验证过程w.r.t到一个模型,即在这种情况下说
用户

现在您的老用户已经注册并确认,所以这真的不是问题。
加密密码
哈希密码
仍在用户表中,供用户访问

你需要担心什么?

=>您可能需要担心
验证\u用户过滤器。我猜,因为他们都使用
bcrypt
身份验证不会是一个真正的问题。如果
OmniAuth
不是,那么它对用户进行身份验证的方式可能会完全不同,您的代码也会崩溃


你唯一需要关心的就是我的感受。

我不认为你遗漏了任何重要的东西。两者都在使用
bcrypt
。令人惊叹的。 但这有关系吗?我想真的有关系

Desive完成您的身份验证过程w.r.t到一个模型,即在这种情况下说
用户

现在您的老用户已经注册并确认,所以这真的不是问题。
加密密码
哈希密码
仍在用户表中,供用户访问

你需要担心什么?

=>您可能需要担心
验证\u用户过滤器。我猜,因为他们都使用
bcrypt
身份验证不会是一个真正的问题。如果
OmniAuth
不是,那么它对用户进行身份验证的方式可能会完全不同,您的代码也会崩溃


你唯一需要注意的就是我的感受。

设计密码与omniauth身份不直接兼容

的确,他们都使用bcrypt来散列密码,然而designe在密码中添加了一个“胡椒”。您必须向omniauth标识添加代码以支持“pepper”

  • OmniAuth身份-
  • 设计—
给你的密码加胡椒粉 Desive会在密码中添加一个胡椒粉(因为它已经被bcrypt腌制),因此为了让Desive用户迁移到omniauth身份,您必须教会身份策略如何添加密码胡椒粉。这个snippit适合我们,但是我们没有更改Desive中的:拉伸配置选项

# snatch the pepper setting from the devise initializer
pepper = "biglonguglystringfromyourdeviseinitializer"

# password created by devise in your db (i.e. "my_password_123")
encrypted_password = "$2a$10$iU.Br8ZClxuqldJt8Evl5OaBbHPJeBWbGV/1RoUsaNIZMBo8wHYTq" 

# pepper the password then compare it using BCrypt like identity does
BCrypt::Password.new(encrypted_password) == "my_password_123#{pepper}"
 => true
我们是怎么做到的 这是一个非常快速和肮脏的猴子补丁,我们用来使它的工作。我们正在研究如何以更合适的方式添加此功能

# file: ~/railsapp/config/initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
  provider :identity
end


module OmniAuth
  module Identity
    module SecurePassword
      module InstanceMethodsOnActivation
        # Returns self if the password is correct, otherwise false.
        def authenticate(unencrypted_password)
          pepper = "the big pepper string from the devise initializer"
          if BCrypt::Password.new(password_digest) == "#{unencrypted_password}#{pepper}"
            self
          else
            false
          end
        end

        # Encrypts the password into the password_digest attribute.
        def password=(unencrypted_password)
          pepper = "the big pepper string from the devise initializer"
          @password = unencrypted_password
          unless unencrypted_password.empty?
            self.password_digest = BCrypt::Password.create("#{unencrypted_password}#{pepper}")
          end
        end
      end
    end
  end
end

设计密码与omniauth身份不直接兼容

的确,他们都使用bcrypt来散列密码,然而designe在密码中添加了一个“胡椒”。您必须向omniauth标识添加代码以支持“pepper”

  • OmniAuth身份-
  • 设计—
给你的密码加胡椒粉 Desive会在密码中添加一个胡椒粉(因为它已经被bcrypt腌制),因此为了让Desive用户迁移到omniauth身份,您必须教会身份策略如何添加密码胡椒粉。这个snippit适合我们,但是我们没有更改Desive中的:拉伸配置选项

# snatch the pepper setting from the devise initializer
pepper = "biglonguglystringfromyourdeviseinitializer"

# password created by devise in your db (i.e. "my_password_123")
encrypted_password = "$2a$10$iU.Br8ZClxuqldJt8Evl5OaBbHPJeBWbGV/1RoUsaNIZMBo8wHYTq" 

# pepper the password then compare it using BCrypt like identity does
BCrypt::Password.new(encrypted_password) == "my_password_123#{pepper}"
 => true
我们是怎么做到的 这是一个非常快速和肮脏的猴子补丁,我们用来使它的工作。我们正在研究如何以更合适的方式添加此功能

# file: ~/railsapp/config/initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
  provider :identity
end


module OmniAuth
  module Identity
    module SecurePassword
      module InstanceMethodsOnActivation
        # Returns self if the password is correct, otherwise false.
        def authenticate(unencrypted_password)
          pepper = "the big pepper string from the devise initializer"
          if BCrypt::Password.new(password_digest) == "#{unencrypted_password}#{pepper}"
            self
          else
            false
          end
        end

        # Encrypts the password into the password_digest attribute.
        def password=(unencrypted_password)
          pepper = "the big pepper string from the devise initializer"
          @password = unencrypted_password
          unless unencrypted_password.empty?
            self.password_digest = BCrypt::Password.create("#{unencrypted_password}#{pepper}")
          end
        end
      end
    end
  end
end

哇,谢谢,这很有道理,我认为胡椒粉总是和bcrypt一起使用。我们向Omniauth的移动被搁置,但这将在不久的将来变得有用。哇,谢谢,这很有意义,我认为pepper总是与bcrypt一起使用。我们向Omniauth的移动被搁置,但这将在不久的将来发挥作用。