Rails 3/Devise:密码盐不再被创建?

Sha*_*non 25 authentication encryption ruby-on-rails salt devise

我一直在研究一个项目,现在使用Devise进行用户身份验证.无论何时创建用户,它都会为它们生成密码盐以及加密密码.

当我进入这个项目的尾端时,我正在测试用户注册,并注意到我的新角色没有为这些新用户在数据库中创建密码盐,而我的老用户都有盐.新用户可以签到好,但我担心为什么Devise不再创造盐.

我遇到的Devise唯一的奇怪之处就是当我升级模块并记住日志说有关删除加密的内容时,因为bcrypt现在是默认加密,或者是那种效果.我这样做了......不确定这是否与当前问题有关.

另外,想想也许是我的项目被打包了,我从零开始创建了一个全新的Rails应用程序并添加了Devise,甚至这个新项目也没有为用户创建盐.

在Devise中设置密码盐是否有新方法,或者是否有人知道为什么盐不再被创建?不幸的是,Devise wiki在这个问题上没有太多可说的内容,到目前为止谷歌一直没有成功.

或者......首先是否需要加盐?我想,看起来更安全.

我的用户/设计配置如下.

配置/初始化/ devise.rb

Devise.setup do |config|

  config.mailer_sender = "mail@domain.com"

  require 'devise/orm/active_record'

  config.authentication_keys = [ :login ]

  config.stretches = 10

  config.encryptor = :bcrypt

  # Setup a pepper to generate the encrypted password.
  config.pepper = "79c2bf3b[...]"

end
Run Code Online (Sandbox Code Playgroud)

应用程序/模型/ user.rb

  devise :database_authenticatable, :registerable, :confirmable,
         :recoverable, :rememberable, :trackable, :validatable
Run Code Online (Sandbox Code Playgroud)

UPDATE

我能够在Devise升级之后找到通知,其中包含......

[DEVISE] From version 1.2, there is no need to set your encryptor to bcrypt since encryptors are only enabled if you include :encryptable in your models. To update your app, please:

1) Remove config.encryptor from your initializer;
2) Add t.encryptable to your old migrations;
3) [Optional] Remove password_salt in a new recent migration. Bcrypt does not require it anymore.
Run Code Online (Sandbox Code Playgroud)

因此,如果你坚持使用bcrypt,似乎不推荐使用password_salt,这就解释了为什么它不再被创建了.所以答案,但我的问题的另一部分仍然是......这是一个足够好的做法,还是我应该使用除了bcrypt之外的另一种加密?

Tim*_*pes 32

新版本的devise使用加密密码字段的字符0到29作为salt,并使用该数据库字段中的剩余字符作为加密密码.所以你的密码实际上仍然是用BCrypt腌制的.


Zab*_*bba 15

PerJoséValim:

如果您使用bcrypt,Devise 1.2.1不再需要password_salt列.如果您需要一种盐,我相信有一种名为authentication_salt的方法可用于检索此类值. (资源)