You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In rails console, create a user with password, for example 'secret'
Then exit the console;
Start rails console again, user.valid_password?('secret') will return false!
Problem analysis
valid_password?(password) in lib/sorcey/model.rb doesn't set stretches to specified value. The set_encryption_attributes class method will set stretches. authenticate and encrypt call the set_encryption_attributes method, but valid_password? doesn't.
Temporary solution
I temporarily solved this bug by calling method set_encryption_attributes right after the authenticates_with_sorcery! call in User model.
class User < ApplicationRecord
authenticates_with_sorcery!
set_encryption_attributes # <- here
end
I ran into this bug when migrating from devise, so it's probably not just my problem.
The text was updated successfully, but these errors were encountered:
@bitberry-dev this should be as simple as calling that method from within validate_password?, if you want to open a PR. Otherwise I'll tackle this when I have a moment.
Configuration
0.16.1
2.7.2
rails-6.0.4.1
macOS 11.6
Expected Behavior
@user.valid_password?(correct_password) # should be true
Actual Behavior
@user.valid_password?(correct_password) # but it false
Steps to Reproduce
change the config/initializers/sorcery.rb as below:
In rails console, create a user with password, for example 'secret'
Then exit the console;
Start rails console again,
user.valid_password?('secret')
will return false!Problem analysis
valid_password?(password)
inlib/sorcey/model.rb
doesn't setstretches
to specified value. Theset_encryption_attributes
class method will setstretches
.authenticate
andencrypt
call theset_encryption_attributes
method, butvalid_password?
doesn't.Temporary solution
I temporarily solved this bug by calling method
set_encryption_attributes
right after theauthenticates_with_sorcery!
call in User model.I ran into this bug when migrating from devise, so it's probably not just my problem.
The text was updated successfully, but these errors were encountered: