Forum: Ruby on Rails Encrypting data before saving

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
David (Guest)
on 2006-03-14 01:27

In the pragmatic rails book, a password is hashed and saved using the
callback before_create.  To do this it sets up an accessor called
'password' and saves the SHA1 output in the backend as

I've done a similar thing, but instead of using an accessor I simply use
'password' for both and assign using:

def before_save
  self.password = my_encrypt_function(self.password)

def after_save
  self.password = ''

(I clear it as the actual hash is never needed by my app and I don't
want it in the session)

Is it "wrong" to use only the one property of the model like this,
without using an intermediary accessor?  It seems to work for me, so I'm
assuming that it's OK.  If anybody can tell me otherwise, I'd appreciate

This topic is locked and can not be replied to.