Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8103685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:37:10+00:00 2026-06-05T23:37:10+00:00

I am trying to finish a project. I am working with user models. When

  • 0

I am trying to finish a project. I am working with user models.
When I signup everything seems ok . But when I try to signin the same member I get this error.

We’re sorry, but something went wrong.
heroku logs file shows error as:

BCrypt::Errors::InvalidHash (invalid hash):
  app/controllers/sessions_controller.rb:8:in `create'

my *sessions_controller* is :

class SessionsController < ApplicationController

  def new
  end

   def create
    user = User.find_by_email(params[:session][:email])
    if user && user.authenticate(params[:session][:password])
      sign_in user
      redirect_to user
    else
      flash.now[:error] = 'Invalid email/password combination'
      render 'new'
    end
  end


  def destroy
    sign_out
    redirect_to root_path
  end
end

and user model is :

class User < ActiveRecord::Base
  attr_accessible :email, :name, :nickname,:password, :password_confirmation 
  has_secure_password


  before_save { |user| user.email = email.downcase }
  before_save { |user| user.nickname = nickname.downcase }
  before_save :create_remember_token
....validations......

    private

    def create_remember_token
      self.remember_token = SecureRandom.urlsafe_base64
    end
end 

this is my session.helper

module SessionsHelper

  def sign_in(user)
    cookies.permanent[:remember_token] = user.remember_token
    self.current_user = user
  end
  def signed_in?
    !current_user.nil?
  end

  def current_user=(user)
    @current_user = user
  end

  def current_user
    @current_user ||= User.find_by_remember_token(cookies[:remember_token])
  end

  def sign_out
    self.current_user = nil
    cookies.delete(:remember_token)
  end
end

I tried heroku rake db:migrate, heroku restart.. there is no change.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:37:11+00:00Added an answer on June 5, 2026 at 11:37 pm

    This means that the hash stored in password_digest is not a valid BCrypt hash (including if the field is empty).

    Based on the comments, it looks like you just created the user at a time the has_secure_password wasn’t there, so the password digest never got stored. Look in the database, you’ll probably see that password_digest is empty for that user. Remove the user from the database and re-create with your new working code and it should work.

    While discussing with in the comments though, I made an (incorrect) guess about why the passwords would be wrong, and I already wrote up the explanation. So here it is for any future visitor that does have this problem, even though it doesn’t apply directly here:


    This typically happens when you switch from using SHA1 or another algorithm to BCrypt but fail to re-hash the passwords in BCrypt. Since you don’t have access to the original passwords (or at least you shouldn’t…), it’s a bit ugly to switch because you have to use both BCrypt and the original authentication scheme. For example, if you were using SHA1 before and now use BCrypt, you have to treat the SHA1 password hash as the plain text password for BCrypt input. For example, you might create a BCrypt digest like this:

    sha1_password = Digest::SHA1.hexdigest("#{salt}#{real_password}")
    self.password_digest = BCrypt::Password.create(sha1_password).to_s
    

    Then, you can create bcrypt password_digests based on the sha1 password hashes that you do have access to.

    You would authenticate like this:

    sha1_password = Digest::SHA1.hexdigest("#{salt}#{attempted_password}")
    BCrypt::Password.new(self.password_digest) == sha1_password
    

    I used SHA1 in the above examples, but this will work for other hashing algorithms as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, so I'm trying to finish our simple project for Data Strcutures but there
I'm at my first hackathon and trying to finish my project. I am very
I was trying to create a lzw compression program. But i need to finish
I'm trying create a RCP Application with Eclipse, but I can't get past the
I'm trying to finish up the CSS and markup for my site (jonathanbuys.com), but
I'm trying to finish a site for my friends brother, and everything (almost) works
I'm trying to finish my project with Python and PyQt4 and I'm having an
I am trying to get google maps to work in my android project. I
I am trying to finish writting my news/blog ASP.net C# application and I am
I'm trying to display the Baseline Start, Finish, Cost, and Work values for a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.