BCrypt::Errors::InvalidSalt: invalid salt Devise

匿名 (未验证) 提交于 2019-12-03 02:38:01

问题:

I'm getting this error when i try to create new User, like this

>> User.create(:email=>"nandosousafr@gmail.com", :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 

i've googled and i found a article that lead me to put config.encryptor = :sha1, instead of config.encryptor = :bcrypt, but the problem wasn't solved..

anyone?

回答1:

What if you tried reinstalling the bcrypt-ruby gem?

  # Remove all versions of bcrypt-ruby   sudo gem uninstall bcrypt-ruby    # Install the latest version    sudo gem install bcrypt-ruby 


回答2:

Reinstalling bcrypt-ruby hasn't worked for me.

The bug got fixed in bcrypt-ruby >= 3.1.10, but Rails 3.2 locked on bcrypt-ruby 3.0.x.

Solution would be to either:

  • move to newer Rails version (>=4)
  • use older Ruby version (2.1.x)
  • fork my changes and keep up with security updates by yourself (since currently Rails 3.2 supports only severe security updates)


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!