# Sha1 or md5?

**URL:** <https://www.ruby-forum.com/t/sha1-or-md5/101392>\
**Category:** Rails\
**Created:** [February 5, 2006, 11:14pm UTC](https://www.ruby-forum.com/t/sha1-or-md5/101392 "2006-02-05T23:14:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gonchuki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ccd318/32.png) [@gonchuki](https://www.ruby-forum.com/u/gonchuki)\
**Post date:** [February 5, 2006, 11:14pm UTC](https://www.ruby-forum.com/t/sha1-or-md5/101392/1 "2006-02-05T23:14:50Z")

</div>

I’m building a site that requires user log-in and i have seen the Agile  
book using sha1 for password hashing while R-Forum uses md5.

Is there any compelling argument to use one over the other?

---

<div class="post-metadata">

**Author:** ![gonchuki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ccd318/32.png) [@gonchuki](https://www.ruby-forum.com/u/gonchuki)\
**Post date:** [February 5, 2006, 11:23pm UTC](https://www.ruby-forum.com/t/sha1-or-md5/101392/2 "2006-02-05T23:23:25Z")

</div>

On 2/5/06, Gonzalo R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m building a site that requires user log-in and i have seen the Agile  
> book using sha1 for password hashing while R-Forum uses md5.
> 
> Is there any compelling argument to use one over the other?

Both have problems, both are fine…  
[http://www.schneier.com/blog/archives/2005/02/sha1\_broken.html](http://www.schneier.com/blog/archives/2005/02/sha1_broken.html)

–  
Jonas  
Elfström

---

<div class="post-metadata">

**Author:** ![gonchuki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ccd318/32.png) [@gonchuki](https://www.ruby-forum.com/u/gonchuki)\
**Post date:** [February 5, 2006, 11:26pm UTC](https://www.ruby-forum.com/t/sha1-or-md5/101392/3 "2006-02-05T23:26:27Z")

</div>

MD5 is known to be broken. Completely and utterly. SHA1 has been  
sucessfully attacked, but not broken.

I would go with SHA1 and a good SALT.

---

<div class="post-metadata">

**Author:** ![gonchuki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ccd318/32.png) [@gonchuki](https://www.ruby-forum.com/u/gonchuki)\
**Post date:** [February 6, 2006, 12:44am UTC](https://www.ruby-forum.com/t/sha1-or-md5/101392/4 "2006-02-06T00:44:53Z")

</div>

On 2/5/06, Juraci Krohling C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> MD5 isn’t broken. Some guys could make _colisions_ w/ strings encrypted  
> w/ MD5. It just means that somebody can possibly find a string that  
> corresponds to the MD5 string, originally encripted via another string.  
> Ex.:  
> “somestring” = 123abc123abc123abc123abc123abc123abc  
> “anotherstring” = 123abc123abc123abc123abc123abc123abc

This equals broken. Let me give you a more appropriate example:

“password1” = 123abc123abc123abc123abc123abc123abc  
“anotherpassword” = 123abc123abc123abc123abc123abc123abc

Obviously, its not a trivial task to get a “colision” MD5 string. Its

> just easier to find another vulnerability in your app than to get a  
> colision.

It is not trivial, but not difficult either.

So, both are secure, but _I_ prefer SHA1 because it have a variable

---

<div class="post-metadata">

**Author:** ![gonchuki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ccd318/32.png) [@gonchuki](https://www.ruby-forum.com/u/gonchuki)\
**Post date:** [February 6, 2006, 12:11am UTC](https://www.ruby-forum.com/t/sha1-or-md5/101392/5 "2006-02-06T00:11:43Z")

</div>

MD5 isn’t broken. Some guys could make _colisions_ w/ strings encrypted  
w/ MD5. It just means that somebody can possibly find a string that  
corresponds to the MD5 string, originally encripted via another string.  
Ex.:  
“somestring” = 123abc123abc123abc123abc123abc123abc  
“anotherstring” = 123abc123abc123abc123abc123abc123abc

Obviously, its not a trivial task to get a “colision” MD5 string. Its  
just easier to find another vulnerability in your app than to get a  
colision.

So, both are secure, but _I_ prefer SHA1 because it have a variable  
length, making colisions even harder.

Regards,  
Juca.

---

<div class="post-metadata">

**Author:** ![gonchuki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ccd318/32.png) [@gonchuki](https://www.ruby-forum.com/u/gonchuki)\
**Post date:** [February 6, 2006, 4:16am UTC](https://www.ruby-forum.com/t/sha1-or-md5/101392/6 "2006-02-06T04:16:05Z")

</div>

thanks for all the responses folks. I guess i will be using SHA1 then

and as for this:

Tobias L. wrote:

> That does not equal broken for the purposes of login. An attacker  
> would have to somehow get his hands on the md5 representation which  
> doesn’t leave your db / app space usually.

my argument is based in the case that there could be more than one admin  
on the site so he also has access to the db, and also since i won’t be  
using SSL or anything like that, the user/password hash could be  
sniffed.  
I know, i’m a bit paranoid but you know the drill… you are never  
overzealous enough when it comes to security.

---

<div class="post-metadata">

**Author:** ![gonchuki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ccd318/32.png) [@gonchuki](https://www.ruby-forum.com/u/gonchuki)\
**Post date:** [February 6, 2006, 3:06am UTC](https://www.ruby-forum.com/t/sha1-or-md5/101392/7 "2006-02-06T03:06:31Z")

</div>

That does not equal broken for the purposes of login. An attacker  
would have to somehow get his hands on the md5 representation which  
doesn’t leave your db / app space usually.

> > “somestring” = 123abc123abc123abc123abc123abc123abc  
> > “anotherstring” = 123abc123abc123abc123abc123abc123abc
> 
> This equals broken. Let me give you a more appropriate example:
> 
> “password1” = 123abc123abc123abc123abc123abc123abc  
> “anotherpassword” = 123abc123abc123abc123abc123abc123abc

–  
Tobi  
[http://shopify.com](http://shopify.com) - modern e-commerce software  
[http://typo.leetsoft.com](http://typo.leetsoft.com) - Open source weblog engine  
[http://blog.leetsoft.com](http://blog.leetsoft.com) - Technical weblog

---

<div class="post-metadata">

**Author:** ![gonchuki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ccd318/32.png) [@gonchuki](https://www.ruby-forum.com/u/gonchuki)\
**Post date:** [February 6, 2006, 10:38am UTC](https://www.ruby-forum.com/t/sha1-or-md5/101392/8 "2006-02-06T10:38:20Z")

</div>

Gonzalo R. wrote:

> my argument is based in the case that there could be more than one admin  
> on the site so he also has access to the db, and also since i won’t be  
> using SSL or anything like that, the user/password hash could be  
> sniffed.  
> I know, i’m a bit paranoid but you know the drill… you are never  
> overzealous enough when it comes to security.

Are you using client side SHA1 library? If not… and you are using  
SSL, how exactly are you  
planning on providing security for the administrator’s login  
credentials?

Zach

---

<div class="post-metadata">

**Author:** ![gonchuki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ccd318/32.png) [@gonchuki](https://www.ruby-forum.com/u/gonchuki)\
**Post date:** [February 6, 2006, 5:37pm UTC](https://www.ruby-forum.com/t/sha1-or-md5/101392/9 "2006-02-06T17:37:37Z")

</div>

On 2/5/06, Gonzalo R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> my argument is based in the case that there could be more than one admin  
> on the site so he also has access to the db, and also since i won’t be  
> using SSL or anything like that, the user/password hash could be  
> sniffed.  
> I know, i’m a bit paranoid but you know the drill… you are never  
> overzealous enough when it comes to security.

If someone you don’t trust has access to your database, you have  
bigger problems than reverse engineering a user password.

– James
