2012-07-20 73 views
1

我得到這個錯誤,當我嘗試創建新的用戶,這樣BCrypt ::錯誤:: InvalidSalt:無效鹽制定

>> User.create(:email=>"[email protected]", :password => "hello") 
BCrypt::Errors::InvalidSalt: invalid salt 
from /Library/Ruby/Gems/1.8/gems/bcrypt-ruby-3.0.1/lib/bcrypt.rb:56:in `hash_secret' 
from /Library/Ruby/Gems/1.8/gems/bcrypt-ruby-3.0.1/lib/bcrypt.rb:161:in `create' 
from /Library/Ruby/Gems/1.8/gems/devise-2.1.2/lib/devise/models/database_authenticatable.rb:110:in `password_digest' 
from /Library/Ruby/Gems/1.8/gems/devise-2.1.2/lib/devise/models/database_authenticatable.rb:37:in `password=' 
from /Library/Ruby/Gems/1.8/gems/activerecord-3.2.2/lib/active_record/attribute_assignment.rb:85:in `send' 
from /Library/Ruby/Gems/1.8/gems/activerecord-3.2.2/lib/active_record/attribute_assignment.rb:85:in `assign_attributes' 
from /Library/Ruby/Gems/1.8/gems/activerecord-3.2.2/lib/active_record/attribute_assignment.rb:78:in `each' 
from /Library/Ruby/Gems/1.8/gems/activerecord-3.2.2/lib/active_record/attribute_assignment.rb:78:in `assign_attributes' 
from /Library/Ruby/Gems/1.8/gems/activerecord-3.2.2/lib/active_record/base.rb:495:in `initialize' 
from /Library/Ruby/Gems/1.8/gems/activerecord-3.2.2/lib/active_record/persistence.rb:44:in `new' 
from /Library/Ruby/Gems/1.8/gems/activerecord-3.2.2/lib/active_record/persistence.rb:44:in `create' 
from (irb):3 

>

的Gemfile

require 'rbconfig' 
HOST_OS = RbConfig::CONFIG['host_os'] 

source 'https://rubygems.org' 

gem 'rails', '3.2.2' 

# Bundle edge Rails instead: 
# gem 'rails', :git => 'git://github.com/rails/rails.git' 

gem 'mysql2' 

# Gems used only for assets and not required 
# in production environments by default. 
group :assets do 
    gem 'sass-rails', '~> 3.2.3' 
    gem 'coffee-rails', '~> 3.2.1' 
    gem "compass-rails" 
    # See https://github.com/sstephenson/execjs#readme for more supported runtimes 
    # gem 'therubyracer' 
    gem 'less' 
    gem 'uglifier', '>= 1.0.3' 
end 

gem 'jquery-rails' 

gem 'twitter-bootstrap-rails' 

gem "friendly_id", "~> 4.0.1" 

gem "rest-client" 

gem "haml", ">= 3.1.6" 
gem "haml-rails", ">= 0.3.4", :group => :development 

gem "devise", ">= 2.1.0" 
gem "cancan", ">= 1.6.7" 
gem "rolify", ">= 3.1.0" 
gem "therubyracer", :group => :assets, :platform => :ruby 
gem "simple_form" 
gem "will_paginate", ">= 3.0.3" 
gem "paperclip", "~> 2.7" 
gem "rdiscount" 
gem 'oily_png' 

User.rb

class User < ActiveRecord::Base 
    # Include default devise modules. Others available are: 
    # :token_authenticatable, :confirmable, 
    # :lockable, :timeoutable and :omniauthable 
    devise :database_authenticatable, :registerable, 
     :recoverable, :rememberable, :trackable, :validatable 

    # Setup accessible (or protected) attributes for your model 
    attr_accessible :email, :password, :password_confirmation, :remember_me 
end 

我GOOGLE了,我發現,導致我把config.encryptor一篇=:SHA1,而不是config.encryptor =:bcrypt,但沒有解決問題..

的人?

+0

我假設你在'your_app/config/intializers'文件夾中有'devise.rb'? – 2012-07-20 13:38:48

+0

是的..我試着用sha1代替brypt。但沒有.. – 2012-07-20 13:54:42

+0

你可以粘貼你的User.rb和你的Gemfile – 2012-07-20 13:57:02

回答

1

如果您嘗試重新安裝bcrypt-ruby寶石,該怎麼辦?

# Remove all versions of bcrypt-ruby 
    sudo gem uninstall bcrypt-ruby 

    # Install the latest version 
    sudo gem install bcrypt-ruby 
+1

謝謝,它現在的工作... – 2012-07-23 16:33:16

+0

沒問題。很高興爲你工作。 – 2012-07-24 02:21:54

0

重新安裝bcrypt-ruby沒有爲我工作。

bcrypt旁註> = 3.1.10蟲子got fixed,但Rails的3.2鎖定bcrypt-紅寶石3.0.x的

的解決辦法是要麼:

  • 移動到新的Rails版本(> = 4)
  • 使用舊版本的Ruby(的2.1.x)
  • my changes並跟上安全更新(因爲目前Rails 3.2只支持嚴重的安全更新)
+0

bcrypt-ruby 3.1.9不存在作爲寶石, – shigazaru 2016-04-01 13:46:31

+0

是的,它不是尚未發佈,不幸的是。你可以直接從Github使用它:'gem「bcrypt-ruby」,github:「codahale/bcrypt-ruby」,ref:「1f9184a」'。鏈接到提交:https://github.com/codahale/bcrypt-ruby/commit/1f9184a8df2b90fa02d01a32a364eefc9072e1b9 – yukas 2016-04-01 20:47:24

+0

不,寶石已被重命名爲只是'bcrypt' – shigazaru 2016-10-21 03:13:26