Skip to content

Password#password_changed? returns true when transitioning crypto providers #721

@pduey

Description

@pduey
  • This is not a usage question.
  • This is not a security issue.
  • I am committed to implementing this feature in a reasonable amount of
    time, and responding promptly to feedback.

Current Behavior

Upgraded from authlogic 3 (to 5.1.0), added:

c.transition_from_crypto_providers = [Authlogic::CryptoProviders::Sha512]
c.crypto_provider = Authlogic::CryptoProviders::SCrypt

Now, whenever a user signs in with their existing password it gets rehashed using SCrypt, however the password_changed? method returns true, even though the password (what the user enters) has not really changed, only the crypted password and salt.

In my app, certain events are triggered if the password has changed. Specifically, a password changed notification. Now my users are confused.

I added this as a feature, because I guess it could be argued it's not a bug, per se.

Proposed Behavior

If the only change is rehashing the password, password_changed? should return false.

Proposed Solution

          def transition_password(attempted_password)
            self.password = attempted_password
+           @password_changed = false
            save(validate: false)
          end

Password#password= sets @password_changed = true, so this would override that.

Alternatively, a new accessor called password_transitioned could be added so the current behavior is unchanged, then I can include that in my conditions.

Personally, I can't think of a case where I'd expect password_changed? to return true unless the user actually changed their original password. If I want to know if the encrypted password changed, I could use the active record generated attribute method, so to me just plain password means the value that the user enters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions