Hello Nicholas,
When Ohm loads the attributes from the database, it doesn't assign it
to @attributes directly. Instead, it uses the accessor to allow for
any kinds of type casting. In your case, what's happening is that each
time Ohm loads the password field from Redis, it processes it again
with BCrypt. To see the code in question, check here:
https://github.com/soveran/ohm/blob/50f0dd780af5db7e8a88253212db5761af025cc5/lib/ohm.rb#L1468-L1471
What we usually do is a bit different: we define an attribute
`crypted_password` in Ohm, and then in the model we define a method
`password=` that takes a string and produces the crypted version,
which is then stored in the `crypted_password` attribute. We use a gem
called Shield, here's the relevant code:
https://github.com/cyx/shield/blob/a67dd135cb5c267ddfc95753b49883ee21aad5b5/lib/shield.rb#L95-L97
You can do something similar to what we do with Shield and use BCrypt
instead. You have to define an attribute `crypted_password`, then a
method called `password=` that is a bit different from what you
currently have:
class User < Ohm::Model
attribute :username
attribute :crypted_password
index :username
def password= string
self.crypted_password = BCrypt::Password.create(string)
end
end
That should work, and you will have to use `crypted_password` for
authenticating users.
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Ohm Ruby" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
ohm-ruby+u...@googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.