Forum: Ruby on Rails Encrypt/ Decrypt password

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Sainaba S. (Guest)
on 2006-01-23 13:35
Hi,

I have user add/edit forms.While creating a user I tried the following
method to encrypt password and stored the encrypted password in the
table.

def self.sha1(pass)
     Digest::SHA1.hexdigest("#{salt}--#{pass}--")
   end

    But when I try to edit the page I get the encrypted password in the
password field  instead of the decrypted password. Is there any method
to decrypt the stored password.

Thanks.
Sainaba.
Rob B. (Guest)
on 2006-01-23 15:40
(Received via mailing list)
Nope!  That's why the digest works so well as an encrypted password.

You probably don't want to edit the password as much as request
Old/New/Confirmed-new to verify that the Old produces the same digest
as what is stored, then save your New (assuming
validates_confirmation_of, that is).

-Rob
Bakki K. (Guest)
on 2006-01-25 00:39
(Received via mailing list)
You might look at sentry which does both encryption/decryption.
http://sentry.rubyforge.org/
-bakki kudva
Yonatan (Guest)
on 2007-07-04 11:30
Sainaba Sainu wrote:
> Hi,
>
> I have user add/edit forms.While creating a user I tried the following
> method to encrypt password and stored the encrypted password in the
> table.
>
> def self.sha1(pass)
>      Digest::SHA1.hexdigest("#{salt}--#{pass}--")
>    end
>
>     But when I try to edit the page I get the encrypted password in the
> password field  instead of the decrypted password. Is there any method
> to decrypt the stored password.
>
> Thanks.
> Sainaba.

YES.
just add this line before "def self.sha1(pass)..."

before_update :crypt_password
This topic is locked and can not be replied to.