# Encrypt passwords in the database

**URL:** <https://www.ruby-forum.com/t/encrypt-passwords-in-the-database/167578>\
**Category:** Rails\
**Created:** [May 9, 2009, 5:17pm UTC](https://www.ruby-forum.com/t/encrypt-passwords-in-the-database/167578 "2009-05-09T17:17:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lakridserne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/94ad74/32.png) [@Lakridserne](https://www.ruby-forum.com/u/Lakridserne)\
**Post date:** [May 9, 2009, 5:17pm UTC](https://www.ruby-forum.com/t/encrypt-passwords-in-the-database/167578/1 "2009-05-09T17:17:31Z")

</div>

Hi,

I know that there is a way to encrypt passwords, but what would be the  
easiest?  
For example you have 2 functions in php. You use them by calling:

fuction(“data-to-be-encrypted-here”);

But is there a similar way in ruby on rails?

---

<div class="post-metadata">

**Author:** ![Lakridserne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/94ad74/32.png) [@Lakridserne](https://www.ruby-forum.com/u/Lakridserne)\
**Post date:** [May 9, 2009, 5:38pm UTC](https://www.ruby-forum.com/t/encrypt-passwords-in-the-database/167578/2 "2009-05-09T17:38:38Z")

</div>

You can use one of the Ruby digest package:  
[http://www.ruby-doc.org/stdlib/libdoc/digest/rdoc/index.html](http://www.ruby-doc.org/stdlib/libdoc/digest/rdoc/index.html)

For example, if you want to digest a password with SHA 512:

require ‘digest/sha2’

Digest::SHA2.hexdigest(‘password’, 512)

Regards.

Franco C…

---

<div class="post-metadata">

**Author:** ![Lakridserne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/94ad74/32.png) [@Lakridserne](https://www.ruby-forum.com/u/Lakridserne)\
**Post date:** [May 12, 2009, 10:54pm UTC](https://www.ruby-forum.com/t/encrypt-passwords-in-the-database/167578/3 "2009-05-12T22:54:53Z")

</div>

Thanks. I looked at it, but could not understand it. I will use md5  
because I also use it in my PHP-applications, and I can therefore use  
the same data without reset users passwords and so on. Can I do that  
and how?

---

<div class="post-metadata">

**Author:** ![Lakridserne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/94ad74/32.png) [@Lakridserne](https://www.ruby-forum.com/u/Lakridserne)\
**Post date:** [May 13, 2009, 5:27am UTC](https://www.ruby-forum.com/t/encrypt-passwords-in-the-database/167578/4 "2009-05-13T05:27:53Z")

</div>

Is the same thing:

require ‘digest’

Digest::MD5.hexdigest(‘password’)

You need to know how to read an API, you must use it every day … The  
“always open” are:

[RDoc Documentation](http://www.ruby-doc.org/core/) and [http://api.rubyonrails.org/](http://api.rubyonrails.org/)

Expend a while figuring it out.

Regards.

Franco C…

---

<div class="post-metadata">

**Author:** ![Lakridserne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/94ad74/32.png) [@Lakridserne](https://www.ruby-forum.com/u/Lakridserne)\
**Post date:** [May 13, 2009, 6:36am UTC](https://www.ruby-forum.com/t/encrypt-passwords-in-the-database/167578/5 "2009-05-13T06:36:55Z")

</div>

Thanks that helped
