Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user.valid_password? not work if encrypt provider is sha512 and user.stretches has specified #769

Open
holysoros opened this issue Apr 20, 2016 · 3 comments

Comments

@holysoros
Copy link

holysoros commented Apr 20, 2016

How to reproduce the bug

change the config/initializers/sorcery.rb as below:

user.stretches = 10
user.encryption_algorithm = :sha512

In rails console, create a user with password, for example 'secretpass'

Then exit the console;

Start rails console again, user.valid_password?(secretpass) will return false!

Problem Analysis

valid_password?(pass) in lib/sorcey/model.rb don't set stretches to value user specified. The set_encryption_attributes class method will set stretches, authenticate and encrypt will call the set_encryption_attributes class method, but valid_password? don't.

Proposed Solution

call set_encryption_attributes in authenticates_with_sorcery! as below:

module Sorcery
  module Model
    def authenticates_with_sorcery!
      ...
      ::Sorcery::Controller::Config.user_config.tap{|blk| blk.call(@sorcery_config) if blk}
      set_encryption_attributes
      ...
    end
  end
end
@bitberry-dev
Copy link

Hi guys, I have the same problem, fixed in a similar way.

@joshbuker
Copy link
Contributor

I wasn't a huge fan of how this overwriting of a singleton config worked, so this will be changed in v1 to no longer be an issue. The config values will live on the instance of the hashing provider instead: sorcery-core/lib/sorcery/config.rb

@bitberry-dev if this is still an issue in the latest version of Sorcery (v0.16.1), can you please open an issue on the current repo? Sorcery/sorcery - Create new issue

@bitberry-dev
Copy link

@athix Of course, I will re-check this bug soon and open a new issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants