# Encrypting password

**URL:** <https://www.ruby-forum.com/t/encrypting-password/108144>\
**Category:** Rails\
**Created:** [June 29, 2007, 12:32pm UTC](https://www.ruby-forum.com/t/encrypting-password/108144 "2007-06-29T12:32:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![unnikrishnanes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/ce73a5/32.png) [@unnikrishnanes](https://www.ruby-forum.com/u/unnikrishnanes)\
**Post date:** [June 29, 2007, 12:32pm UTC](https://www.ruby-forum.com/t/encrypting-password/108144/1 "2007-06-29T12:32:04Z")

</div>

Hi all

is there any way to encrypt password in ruby like sha1(‘password’) or  
md5(‘password’) in PHP?

please help

---

<div class="post-metadata">

**Author:** ![unnikrishnanes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/ce73a5/32.png) [@unnikrishnanes](https://www.ruby-forum.com/u/unnikrishnanes)\
**Post date:** [June 29, 2007, 12:45pm UTC](https://www.ruby-forum.com/t/encrypting-password/108144/2 "2007-06-29T12:45:55Z")

</div>

require ‘digest/sha1’  
sha1 = Digest::SHA1.hexdigest(‘something secret’)

Unni K. wrote:

> is there any way to encrypt password in ruby like sha1(‘password’) or  
> md5(‘password’) in PHP?

---

<div class="post-metadata">

**Author:** ![unnikrishnanes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/ce73a5/32.png) [@unnikrishnanes](https://www.ruby-forum.com/u/unnikrishnanes)\
**Post date:** [June 29, 2007, 1:05pm UTC](https://www.ruby-forum.com/t/encrypting-password/108144/3 "2007-06-29T13:05:56Z")

</div>

Thank you for your reply…

But where should i write this.

## I have a controller called say\_controller.rb

class SayController \<ApplicationController

def first

end

def second

end

## end

first.rhtml have password field where one can enter their password.

so I have to write

" require ‘digest/sha1’  
sha1 = Digest::SHA1.hexdigest(‘something secret’)"

where and how

thanks in advance

Florencio C. wrote:

> require ‘digest/sha1’  
> sha1 = Digest::SHA1.hexdigest(‘something secret’)
> 
> Unni K. wrote:
> 
> > is there any way to encrypt password in ruby like sha1(‘password’) or  
> > md5(‘password’) in PHP?

---

<div class="post-metadata">

**Author:** ![unnikrishnanes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/ce73a5/32.png) [@unnikrishnanes](https://www.ruby-forum.com/u/unnikrishnanes)\
**Post date:** [June 29, 2007, 1:36pm UTC](https://www.ruby-forum.com/t/encrypting-password/108144/4 "2007-06-29T13:36:01Z")

</div>

Hello.

If you want to crypt a password between the client and the server, you  
should use SSL between them. SH1 or MD5 encryption, like the one  
provided with ruby/php are used to crypt password on the server side.

Tony

---

<div class="post-metadata">

**Author:** ![unnikrishnanes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/ce73a5/32.png) [@unnikrishnanes](https://www.ruby-forum.com/u/unnikrishnanes)\
**Post date:** [June 29, 2007, 1:12pm UTC](https://www.ruby-forum.com/t/encrypting-password/108144/5 "2007-06-29T13:12:10Z")

</div>

Best place would be your user model.

Kind regards  
Nicolai
