Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This means that the hash stored in <code>password_digest</code> is not a valid BCrypt hash (including if the field is empty).</p> <p>Based on the comments, it looks like you just created the user at a time the <code>has_secure_password</code> wasn't there, so the password digest never got stored. Look in the database, you'll probably see that <code>password_digest</code> is empty for that user. Remove the user from the database and re-create with your new working code and it should work.</p> <p>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:</p> <hr> <p>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 <em>both</em> 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 <em>as</em> the plain text password for BCrypt input. For example, you might create a BCrypt digest like this:</p> <pre><code>sha1_password = Digest::SHA1.hexdigest("#{salt}#{real_password}") self.password_digest = BCrypt::Password.create(sha1_password).to_s </code></pre> <p>Then, you can create bcrypt password_digests based on the sha1 password hashes that you <em>do</em> have access to.</p> <p>You would authenticate like this:</p> <pre><code>sha1_password = Digest::SHA1.hexdigest("#{salt}#{attempted_password}") BCrypt::Password.new(self.password_digest) == sha1_password </code></pre> <p>I used SHA1 in the above examples, but this will work for other hashing algorithms as well.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload