Michael Hartl Ruby on Rails Tutorial Chapter 9 Failing Tests Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!“BCrypt::Errors::InvalidHash” when trying to sign inHow can I “pretty” format my JSON output in Ruby on Rails?A concise explanation of nil v. empty v. blank in Ruby on RailsHow can I rename a database column in a Ruby on Rails migration?How do I get the current absolute URL in Ruby on Rails?Ruby on Rails Server optionsPurge or recreate a Ruby on Rails databaseRuby on Rails Tutorial by Michael Hartl. Failing test in Chapter 8.29Ruby on Rails Tutorial by Michael Hartl. Failing Test in Chapter 9.1Ruby on Rails Tutorial by Michael Hartl. Chapter 9 Failing testsRails 4 - My current_user logic is not working properly - Michael Hartl Rails 4.0 Tutorial

How would this chord from "Rocket Man" be analyzed?

Is there any hidden 'W' sound after 'comment' in : Comment est-elle?

Do you need a weapon for Thunderous Smite, and the other 'Smite' spells?

Is a 5 watt UHF/VHF handheld considered QRP?

Israeli soda type drink

Flash for group photos near wall

Arriving in Atlanta after US Preclearance in Dublin. Will I go through TSA security in Atlanta to transfer to a connecting flight?

Identify story/novel: Tribe on colonized planet, not aware of this. "Taboo," altitude sickness, robot guardian (60s? Young Adult?)

I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?

What was Apollo 13's "Little Jolt" after MECO?

How long after the last departure shall the airport stay open for an emergency return?

Refugee travel document from Spain to US

Seek and ye shall find

As an international instructor, should I openly talk about my accent?

Are all CP/M-80 implementations binary compatible?

Error: Syntax error. Missing ')' for CASE Statement

Map material from china not allowed to leave the country

Would reducing the reference voltage of an ADC have any effect on accuracy?

What is /etc/mtab in Linux?

Why does the Cisco show run command not show the full version, while the show version command does?

Can I criticise the more senior developers around me for not writing clean code?

Protagonist's race is hidden - should I reveal it?

A strange hotel

Is Diceware more secure than a long passphrase?



Michael Hartl Ruby on Rails Tutorial Chapter 9 Failing Tests



Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!“BCrypt::Errors::InvalidHash” when trying to sign inHow can I “pretty” format my JSON output in Ruby on Rails?A concise explanation of nil v. empty v. blank in Ruby on RailsHow can I rename a database column in a Ruby on Rails migration?How do I get the current absolute URL in Ruby on Rails?Ruby on Rails Server optionsPurge or recreate a Ruby on Rails databaseRuby on Rails Tutorial by Michael Hartl. Failing test in Chapter 8.29Ruby on Rails Tutorial by Michael Hartl. Failing Test in Chapter 9.1Ruby on Rails Tutorial by Michael Hartl. Chapter 9 Failing testsRails 4 - My current_user logic is not working properly - Michael Hartl Rails 4.0 Tutorial



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-1















I tried looking for an answer to this question, but to no avail.



I'm getting this error message when I run rails test.



 1) Error:
UsersLoginTest#test_login_with_valid_information_followed_by_logout:
ActionView::Template::Error: invalid hash
app/models/user.rb:32:in `new'
app/models/user.rb:32:in `authenticated?'
app/helpers/sessions_helper.rb:21:in `current_user'
app/helpers/sessions_helper.rb:30:in `logged_in?'
app/views/layouts/_header.html.erb:8:in `_app_views_layouts__header_html_erb__454288832_69555624'
app/views/layouts/application.html.erb:9:in `_app_views_layouts_application_html_erb___219463369_68483868'
test/integration/users_login_test.rb:45:in `block in <class:UsersLoginTest>'

24 runs, 66 assertions, 0 failures, 1 errors, 0 skips


Here are the relevant files, any help would be greatly appreciated



Thanks!



from user.rb



 # Returns the hash digest of the given string.
def User.digest(string)
cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST :
BCrypt::Engine.cost
BCrypt::Password.create(string, cost: cost)
end

# Returns a random token.
def User.new_token
SecureRandom.urlsafe_base64
end

# Remembers a user in the database for use in persistent sessions.
def remember
self.remember_token = User.new_token
update_attribute(:remember_digest, User.digest(remember_token))
end

# Returns true if the given token matches the digest.
def authenticated?(remember_token)
BCrypt::Password.new(remember_digest).is_password?(remember_token)
end

# Forgets a user
def forget
update_attribute(:remember_digest, nil)
end


from sessions_helper.rb



 def current_user
if (user_id = session[:user_id])
@current_user ||= User.find_by(id: user_id)
elsif (user_id = cookies.signed[:user_id])
user = User.find_by(id: user_id)
if user && user.authenticated?(cookies[:remember_token])
log_in user
@current_user = user
end
end
end

# Returns true if the user is logged in, false otherwise.
def logged_in?
!current_user.nil?
end


require 'test_helper'

class UsersLoginTest < ActionDispatch::IntegrationTest

def setup
@user = users(:michael)
end

test "login with invalid information" do
get login_path
assert_template 'sessions/new'
post login_path, params: session: email: "", password: ""
assert_template 'sessions/new'
assert_not flash.empty?
get root_path
assert flash.empty?
end

test "login with valid information" do
get login_path
post login_path, params: session: email: @user.email,
password: 'password'
assert_redirected_to @user
follow_redirect!
assert_template 'users/show'
assert_select "a[href=?]", login_path, count: 0
assert_select "a[href=?]", logout_path
assert_select "a[href=?]", user_path(@user)
end

test "login with valid information followed by logout" do
get login_path
post login_path, params: session: email: @user.email,
password: 'password'
assert is_logged_in?
assert_redirected_to @user
follow_redirect!
assert_template 'users/show'
assert_select "a[href=?]", login_path, count: 0
assert_select "a[href=?]", logout_path
assert_select "a[href=?]", user_path(@user)
delete logout_path
assert_not is_logged_in?
assert_redirected_to root_url
follow_redirect!
assert_select "a[href=?]", login_path
assert_select "a[href=?]", logout_path, count: 0
assert_select "a[href=?]", user_path(@user), count: 0
end
end


Edit: I won't allow any me to post anymore code, so if there's anything you'd need to see, let me know!










share|improve this question
























  • Did you read any of the 69 search results for the exact same chapter of the exact same book before you posted your question? It would be great if you included in your post what things you have tried from those duplicative questions and answers so anyone answering your question doesn't give you an answer you have already tried and failed to get working. I don't see anything at all in your post about what you've done to solve this on your own.

    – anothermh
    Mar 22 at 19:11











  • Possible duplicate of "BCrypt::Errors::InvalidHash" when trying to sign in

    – anothermh
    Mar 23 at 2:01

















-1















I tried looking for an answer to this question, but to no avail.



I'm getting this error message when I run rails test.



 1) Error:
UsersLoginTest#test_login_with_valid_information_followed_by_logout:
ActionView::Template::Error: invalid hash
app/models/user.rb:32:in `new'
app/models/user.rb:32:in `authenticated?'
app/helpers/sessions_helper.rb:21:in `current_user'
app/helpers/sessions_helper.rb:30:in `logged_in?'
app/views/layouts/_header.html.erb:8:in `_app_views_layouts__header_html_erb__454288832_69555624'
app/views/layouts/application.html.erb:9:in `_app_views_layouts_application_html_erb___219463369_68483868'
test/integration/users_login_test.rb:45:in `block in <class:UsersLoginTest>'

24 runs, 66 assertions, 0 failures, 1 errors, 0 skips


Here are the relevant files, any help would be greatly appreciated



Thanks!



from user.rb



 # Returns the hash digest of the given string.
def User.digest(string)
cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST :
BCrypt::Engine.cost
BCrypt::Password.create(string, cost: cost)
end

# Returns a random token.
def User.new_token
SecureRandom.urlsafe_base64
end

# Remembers a user in the database for use in persistent sessions.
def remember
self.remember_token = User.new_token
update_attribute(:remember_digest, User.digest(remember_token))
end

# Returns true if the given token matches the digest.
def authenticated?(remember_token)
BCrypt::Password.new(remember_digest).is_password?(remember_token)
end

# Forgets a user
def forget
update_attribute(:remember_digest, nil)
end


from sessions_helper.rb



 def current_user
if (user_id = session[:user_id])
@current_user ||= User.find_by(id: user_id)
elsif (user_id = cookies.signed[:user_id])
user = User.find_by(id: user_id)
if user && user.authenticated?(cookies[:remember_token])
log_in user
@current_user = user
end
end
end

# Returns true if the user is logged in, false otherwise.
def logged_in?
!current_user.nil?
end


require 'test_helper'

class UsersLoginTest < ActionDispatch::IntegrationTest

def setup
@user = users(:michael)
end

test "login with invalid information" do
get login_path
assert_template 'sessions/new'
post login_path, params: session: email: "", password: ""
assert_template 'sessions/new'
assert_not flash.empty?
get root_path
assert flash.empty?
end

test "login with valid information" do
get login_path
post login_path, params: session: email: @user.email,
password: 'password'
assert_redirected_to @user
follow_redirect!
assert_template 'users/show'
assert_select "a[href=?]", login_path, count: 0
assert_select "a[href=?]", logout_path
assert_select "a[href=?]", user_path(@user)
end

test "login with valid information followed by logout" do
get login_path
post login_path, params: session: email: @user.email,
password: 'password'
assert is_logged_in?
assert_redirected_to @user
follow_redirect!
assert_template 'users/show'
assert_select "a[href=?]", login_path, count: 0
assert_select "a[href=?]", logout_path
assert_select "a[href=?]", user_path(@user)
delete logout_path
assert_not is_logged_in?
assert_redirected_to root_url
follow_redirect!
assert_select "a[href=?]", login_path
assert_select "a[href=?]", logout_path, count: 0
assert_select "a[href=?]", user_path(@user), count: 0
end
end


Edit: I won't allow any me to post anymore code, so if there's anything you'd need to see, let me know!










share|improve this question
























  • Did you read any of the 69 search results for the exact same chapter of the exact same book before you posted your question? It would be great if you included in your post what things you have tried from those duplicative questions and answers so anyone answering your question doesn't give you an answer you have already tried and failed to get working. I don't see anything at all in your post about what you've done to solve this on your own.

    – anothermh
    Mar 22 at 19:11











  • Possible duplicate of "BCrypt::Errors::InvalidHash" when trying to sign in

    – anothermh
    Mar 23 at 2:01













-1












-1








-1








I tried looking for an answer to this question, but to no avail.



I'm getting this error message when I run rails test.



 1) Error:
UsersLoginTest#test_login_with_valid_information_followed_by_logout:
ActionView::Template::Error: invalid hash
app/models/user.rb:32:in `new'
app/models/user.rb:32:in `authenticated?'
app/helpers/sessions_helper.rb:21:in `current_user'
app/helpers/sessions_helper.rb:30:in `logged_in?'
app/views/layouts/_header.html.erb:8:in `_app_views_layouts__header_html_erb__454288832_69555624'
app/views/layouts/application.html.erb:9:in `_app_views_layouts_application_html_erb___219463369_68483868'
test/integration/users_login_test.rb:45:in `block in <class:UsersLoginTest>'

24 runs, 66 assertions, 0 failures, 1 errors, 0 skips


Here are the relevant files, any help would be greatly appreciated



Thanks!



from user.rb



 # Returns the hash digest of the given string.
def User.digest(string)
cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST :
BCrypt::Engine.cost
BCrypt::Password.create(string, cost: cost)
end

# Returns a random token.
def User.new_token
SecureRandom.urlsafe_base64
end

# Remembers a user in the database for use in persistent sessions.
def remember
self.remember_token = User.new_token
update_attribute(:remember_digest, User.digest(remember_token))
end

# Returns true if the given token matches the digest.
def authenticated?(remember_token)
BCrypt::Password.new(remember_digest).is_password?(remember_token)
end

# Forgets a user
def forget
update_attribute(:remember_digest, nil)
end


from sessions_helper.rb



 def current_user
if (user_id = session[:user_id])
@current_user ||= User.find_by(id: user_id)
elsif (user_id = cookies.signed[:user_id])
user = User.find_by(id: user_id)
if user && user.authenticated?(cookies[:remember_token])
log_in user
@current_user = user
end
end
end

# Returns true if the user is logged in, false otherwise.
def logged_in?
!current_user.nil?
end


require 'test_helper'

class UsersLoginTest < ActionDispatch::IntegrationTest

def setup
@user = users(:michael)
end

test "login with invalid information" do
get login_path
assert_template 'sessions/new'
post login_path, params: session: email: "", password: ""
assert_template 'sessions/new'
assert_not flash.empty?
get root_path
assert flash.empty?
end

test "login with valid information" do
get login_path
post login_path, params: session: email: @user.email,
password: 'password'
assert_redirected_to @user
follow_redirect!
assert_template 'users/show'
assert_select "a[href=?]", login_path, count: 0
assert_select "a[href=?]", logout_path
assert_select "a[href=?]", user_path(@user)
end

test "login with valid information followed by logout" do
get login_path
post login_path, params: session: email: @user.email,
password: 'password'
assert is_logged_in?
assert_redirected_to @user
follow_redirect!
assert_template 'users/show'
assert_select "a[href=?]", login_path, count: 0
assert_select "a[href=?]", logout_path
assert_select "a[href=?]", user_path(@user)
delete logout_path
assert_not is_logged_in?
assert_redirected_to root_url
follow_redirect!
assert_select "a[href=?]", login_path
assert_select "a[href=?]", logout_path, count: 0
assert_select "a[href=?]", user_path(@user), count: 0
end
end


Edit: I won't allow any me to post anymore code, so if there's anything you'd need to see, let me know!










share|improve this question
















I tried looking for an answer to this question, but to no avail.



I'm getting this error message when I run rails test.



 1) Error:
UsersLoginTest#test_login_with_valid_information_followed_by_logout:
ActionView::Template::Error: invalid hash
app/models/user.rb:32:in `new'
app/models/user.rb:32:in `authenticated?'
app/helpers/sessions_helper.rb:21:in `current_user'
app/helpers/sessions_helper.rb:30:in `logged_in?'
app/views/layouts/_header.html.erb:8:in `_app_views_layouts__header_html_erb__454288832_69555624'
app/views/layouts/application.html.erb:9:in `_app_views_layouts_application_html_erb___219463369_68483868'
test/integration/users_login_test.rb:45:in `block in <class:UsersLoginTest>'

24 runs, 66 assertions, 0 failures, 1 errors, 0 skips


Here are the relevant files, any help would be greatly appreciated



Thanks!



from user.rb



 # Returns the hash digest of the given string.
def User.digest(string)
cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST :
BCrypt::Engine.cost
BCrypt::Password.create(string, cost: cost)
end

# Returns a random token.
def User.new_token
SecureRandom.urlsafe_base64
end

# Remembers a user in the database for use in persistent sessions.
def remember
self.remember_token = User.new_token
update_attribute(:remember_digest, User.digest(remember_token))
end

# Returns true if the given token matches the digest.
def authenticated?(remember_token)
BCrypt::Password.new(remember_digest).is_password?(remember_token)
end

# Forgets a user
def forget
update_attribute(:remember_digest, nil)
end


from sessions_helper.rb



 def current_user
if (user_id = session[:user_id])
@current_user ||= User.find_by(id: user_id)
elsif (user_id = cookies.signed[:user_id])
user = User.find_by(id: user_id)
if user && user.authenticated?(cookies[:remember_token])
log_in user
@current_user = user
end
end
end

# Returns true if the user is logged in, false otherwise.
def logged_in?
!current_user.nil?
end


require 'test_helper'

class UsersLoginTest < ActionDispatch::IntegrationTest

def setup
@user = users(:michael)
end

test "login with invalid information" do
get login_path
assert_template 'sessions/new'
post login_path, params: session: email: "", password: ""
assert_template 'sessions/new'
assert_not flash.empty?
get root_path
assert flash.empty?
end

test "login with valid information" do
get login_path
post login_path, params: session: email: @user.email,
password: 'password'
assert_redirected_to @user
follow_redirect!
assert_template 'users/show'
assert_select "a[href=?]", login_path, count: 0
assert_select "a[href=?]", logout_path
assert_select "a[href=?]", user_path(@user)
end

test "login with valid information followed by logout" do
get login_path
post login_path, params: session: email: @user.email,
password: 'password'
assert is_logged_in?
assert_redirected_to @user
follow_redirect!
assert_template 'users/show'
assert_select "a[href=?]", login_path, count: 0
assert_select "a[href=?]", logout_path
assert_select "a[href=?]", user_path(@user)
delete logout_path
assert_not is_logged_in?
assert_redirected_to root_url
follow_redirect!
assert_select "a[href=?]", login_path
assert_select "a[href=?]", logout_path, count: 0
assert_select "a[href=?]", user_path(@user), count: 0
end
end


Edit: I won't allow any me to post anymore code, so if there's anything you'd need to see, let me know!







ruby-on-rails ruby






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 16:03







Evan Medrano

















asked Mar 22 at 15:48









Evan MedranoEvan Medrano

41




41












  • Did you read any of the 69 search results for the exact same chapter of the exact same book before you posted your question? It would be great if you included in your post what things you have tried from those duplicative questions and answers so anyone answering your question doesn't give you an answer you have already tried and failed to get working. I don't see anything at all in your post about what you've done to solve this on your own.

    – anothermh
    Mar 22 at 19:11











  • Possible duplicate of "BCrypt::Errors::InvalidHash" when trying to sign in

    – anothermh
    Mar 23 at 2:01

















  • Did you read any of the 69 search results for the exact same chapter of the exact same book before you posted your question? It would be great if you included in your post what things you have tried from those duplicative questions and answers so anyone answering your question doesn't give you an answer you have already tried and failed to get working. I don't see anything at all in your post about what you've done to solve this on your own.

    – anothermh
    Mar 22 at 19:11











  • Possible duplicate of "BCrypt::Errors::InvalidHash" when trying to sign in

    – anothermh
    Mar 23 at 2:01
















Did you read any of the 69 search results for the exact same chapter of the exact same book before you posted your question? It would be great if you included in your post what things you have tried from those duplicative questions and answers so anyone answering your question doesn't give you an answer you have already tried and failed to get working. I don't see anything at all in your post about what you've done to solve this on your own.

– anothermh
Mar 22 at 19:11





Did you read any of the 69 search results for the exact same chapter of the exact same book before you posted your question? It would be great if you included in your post what things you have tried from those duplicative questions and answers so anyone answering your question doesn't give you an answer you have already tried and failed to get working. I don't see anything at all in your post about what you've done to solve this on your own.

– anothermh
Mar 22 at 19:11













Possible duplicate of "BCrypt::Errors::InvalidHash" when trying to sign in

– anothermh
Mar 23 at 2:01





Possible duplicate of "BCrypt::Errors::InvalidHash" when trying to sign in

– anothermh
Mar 23 at 2:01












1 Answer
1






active

oldest

votes


















0














"BCrypt::Errors::InvalidHash" when trying to sign in Looks like the same issue you're encountering:




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.







share|improve this answer























  • I get the error message when I try to log out. When I check the console, I see that a password_digest value was generated, but I also see that remember_digest is nil. Not sure if that is the issue at hand

    – Evan Medrano
    Mar 22 at 16:00












  • Did you create the user after including the has_secure_password? If so try another user, if the error only occurs with the first user, the problem is their password digest. Recreating that user should solve the issue

    – Mark
    Mar 22 at 16:01











  • Sorry I just saw this is occurring in a spec - can you include the spec where you generate the user please? It's probably an issue there

    – Mark
    Mar 22 at 16:02











  • Just added the test file

    – Evan Medrano
    Mar 22 at 16:04











  • So I just took a look at chapter 9 of the tutorial (yeah it's a Friday afternoon at work)

    – Mark
    Mar 22 at 16:25











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55303344%2fmichael-hartl-ruby-on-rails-tutorial-chapter-9-failing-tests%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














"BCrypt::Errors::InvalidHash" when trying to sign in Looks like the same issue you're encountering:




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.







share|improve this answer























  • I get the error message when I try to log out. When I check the console, I see that a password_digest value was generated, but I also see that remember_digest is nil. Not sure if that is the issue at hand

    – Evan Medrano
    Mar 22 at 16:00












  • Did you create the user after including the has_secure_password? If so try another user, if the error only occurs with the first user, the problem is their password digest. Recreating that user should solve the issue

    – Mark
    Mar 22 at 16:01











  • Sorry I just saw this is occurring in a spec - can you include the spec where you generate the user please? It's probably an issue there

    – Mark
    Mar 22 at 16:02











  • Just added the test file

    – Evan Medrano
    Mar 22 at 16:04











  • So I just took a look at chapter 9 of the tutorial (yeah it's a Friday afternoon at work)

    – Mark
    Mar 22 at 16:25















0














"BCrypt::Errors::InvalidHash" when trying to sign in Looks like the same issue you're encountering:




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.







share|improve this answer























  • I get the error message when I try to log out. When I check the console, I see that a password_digest value was generated, but I also see that remember_digest is nil. Not sure if that is the issue at hand

    – Evan Medrano
    Mar 22 at 16:00












  • Did you create the user after including the has_secure_password? If so try another user, if the error only occurs with the first user, the problem is their password digest. Recreating that user should solve the issue

    – Mark
    Mar 22 at 16:01











  • Sorry I just saw this is occurring in a spec - can you include the spec where you generate the user please? It's probably an issue there

    – Mark
    Mar 22 at 16:02











  • Just added the test file

    – Evan Medrano
    Mar 22 at 16:04











  • So I just took a look at chapter 9 of the tutorial (yeah it's a Friday afternoon at work)

    – Mark
    Mar 22 at 16:25













0












0








0







"BCrypt::Errors::InvalidHash" when trying to sign in Looks like the same issue you're encountering:




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.







share|improve this answer













"BCrypt::Errors::InvalidHash" when trying to sign in Looks like the same issue you're encountering:




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.








share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 22 at 15:57









MarkMark

2,2481725




2,2481725












  • I get the error message when I try to log out. When I check the console, I see that a password_digest value was generated, but I also see that remember_digest is nil. Not sure if that is the issue at hand

    – Evan Medrano
    Mar 22 at 16:00












  • Did you create the user after including the has_secure_password? If so try another user, if the error only occurs with the first user, the problem is their password digest. Recreating that user should solve the issue

    – Mark
    Mar 22 at 16:01











  • Sorry I just saw this is occurring in a spec - can you include the spec where you generate the user please? It's probably an issue there

    – Mark
    Mar 22 at 16:02











  • Just added the test file

    – Evan Medrano
    Mar 22 at 16:04











  • So I just took a look at chapter 9 of the tutorial (yeah it's a Friday afternoon at work)

    – Mark
    Mar 22 at 16:25

















  • I get the error message when I try to log out. When I check the console, I see that a password_digest value was generated, but I also see that remember_digest is nil. Not sure if that is the issue at hand

    – Evan Medrano
    Mar 22 at 16:00












  • Did you create the user after including the has_secure_password? If so try another user, if the error only occurs with the first user, the problem is their password digest. Recreating that user should solve the issue

    – Mark
    Mar 22 at 16:01











  • Sorry I just saw this is occurring in a spec - can you include the spec where you generate the user please? It's probably an issue there

    – Mark
    Mar 22 at 16:02











  • Just added the test file

    – Evan Medrano
    Mar 22 at 16:04











  • So I just took a look at chapter 9 of the tutorial (yeah it's a Friday afternoon at work)

    – Mark
    Mar 22 at 16:25
















I get the error message when I try to log out. When I check the console, I see that a password_digest value was generated, but I also see that remember_digest is nil. Not sure if that is the issue at hand

– Evan Medrano
Mar 22 at 16:00






I get the error message when I try to log out. When I check the console, I see that a password_digest value was generated, but I also see that remember_digest is nil. Not sure if that is the issue at hand

– Evan Medrano
Mar 22 at 16:00














Did you create the user after including the has_secure_password? If so try another user, if the error only occurs with the first user, the problem is their password digest. Recreating that user should solve the issue

– Mark
Mar 22 at 16:01





Did you create the user after including the has_secure_password? If so try another user, if the error only occurs with the first user, the problem is their password digest. Recreating that user should solve the issue

– Mark
Mar 22 at 16:01













Sorry I just saw this is occurring in a spec - can you include the spec where you generate the user please? It's probably an issue there

– Mark
Mar 22 at 16:02





Sorry I just saw this is occurring in a spec - can you include the spec where you generate the user please? It's probably an issue there

– Mark
Mar 22 at 16:02













Just added the test file

– Evan Medrano
Mar 22 at 16:04





Just added the test file

– Evan Medrano
Mar 22 at 16:04













So I just took a look at chapter 9 of the tutorial (yeah it's a Friday afternoon at work)

– Mark
Mar 22 at 16:25





So I just took a look at chapter 9 of the tutorial (yeah it's a Friday afternoon at work)

– Mark
Mar 22 at 16:25



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55303344%2fmichael-hartl-ruby-on-rails-tutorial-chapter-9-failing-tests%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해