7

For a long time as a php developer, i have been using md5 hashing algorithm to secure the password data and to generate unique hashing algorithms.

However from last few months i hear rumors that md5 is not considered secure anymore, i like to know why ?

what are the password authentication alternatives i.e SHA1, password_hash() in PHP 5.5 ? And i like to know why these alternatives are considered better choice now a days, because to me most of these are again just another hashing algorithms ...

mahen3d
  • 7,047
  • 13
  • 51
  • 103

2 Answers2

4

Because many websites and research studies have proved that md5() can be reversed and you should stop using that !

In simple words....

enter image description here

You could very well make use of password_hash() in PHP 5.5 and also the crypt() those are the better ones considered so far.

A simple illustration of password_hash() taken from PHP Manual

<?php
$options = [
    'cost' => 12,
];
echo password_hash("rasmuslerdorf", PASSWORD_BCRYPT, $options)."\n";
?>

A simple illustration of crypt making using of the BLOWFISH algorithm

if (CRYPT_BLOWFISH == 1) {
    echo 'Blowfish:     ' . crypt('rasmuslerdorf', '$2a$07$usesomesillystringforsalt$') . "\n";
}

EDIT :

Why you should not use md5() ?

Hashing algorithms such as MD5, SHA1 and SHA256 are designed to be very fast and efficient. With modern techniques and computer equipment, it has become trivial to "brute force" the output of these algorithms, in order to determine the original input. Because of how quickly a modern computer can "reverse" these hashing algorithms, many security professionals strongly suggest against their use for password hashing.

Why go for password_hash() on PHP 5.5 ?

When hashing passwords, the two most important considerations are the computational expense, and the salt. The more computationally expensive the hashing algorithm, the longer it will take to brute force its output. PHP 5.5 provides a native password hashing API which is the password_hash() that safely handles both hashing and verifying passwords in a secure manner.

Source

Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
  • 1
    You could also consider using `bcrypt` as well. I've found it very secure for my purposes. [link to the github](https://github.com/ircmaxell/password_compat) – Ohgodwhy Mar 03 '14 at 06:16
  • @Ohgodwhy, Good you can feel free to edit my answer with that. **+1** – Shankar Narayana Damodaran Mar 03 '14 at 06:17
  • 1
    Nope. your answer is great as it stands, just adding in my2cp :) – Ohgodwhy Mar 03 '14 at 06:18
  • I for one don't know why that when I try to use `password_hash()` on all my servers (PHP 5.3+) that I get this error message `Fatal error: Call to undefined function password_hash()` @ShankarDamodaran any idea why? The manual says `PHP 5 >= 5.5.0` does that not mean 5.0+ or does it mean that it must be 5.5? – Funk Forty Niner Mar 03 '14 at 06:20
  • 1
    @Fred-ii-, That is because `password_hash()` is available from PHP 5.5 :P , not on versions prior to that. – Shankar Narayana Damodaran Mar 03 '14 at 06:21
  • Ok, thanks Shankar. I don't know why PHP.net shows `PHP 5 >= 5.5.0` I guess I misunderstood what they meant by that, and thought it was PHP 5+ @ShankarDamodaran +1 ;-) – Funk Forty Niner Mar 03 '14 at 06:23
  • i guess my question is mainly why md5 is insecure, and if you say password_hash is better how it can be better than md5.. that the more of the question.. – mahen3d Mar 03 '14 at 06:38
  • The OP is looking for the actual "machine code" or an "assembler" method of explanation (*if you get my meaning*). Seems like the explanations and reasons given, just have not been satisfying enough; till it's too late ;-) @ShankarDamodaran - I for one never liked going to the "School of hard knocks". It's just too painful ;-) Voted to close as "unclear what is asked". – Funk Forty Niner Mar 03 '14 at 07:08
  • Yeah the research studies link I provided earlier (on the top) , exactly explains that :) – Shankar Narayana Damodaran Mar 03 '14 at 07:09
  • 1
    Yes I noticed and even then, you didn't have to go to those lengths, but very very good though! I voted to close as "unclear what is asking". @ShankarDamodaran - Seems there's no pleasing here. Funny graphic by the way! lol – Funk Forty Niner Mar 03 '14 at 07:10
  • 1
    Please elaborate on "many websites and research studies have proved that `md5()` can be reversed". I won’t accept simple look-up or rainbow tables as answer. – Gumbo Mar 03 '14 at 08:48
  • 2
    @Shankar Damodaran: IMHO: No need to duplicate content, also not from the PHP manual (and you miss to give credits even). Also the study you've linked, I wonder how it fits. And the image you've posted, it's pretty low for an answer to my taste. Especially due to the duplicate material. – hakre Mar 03 '14 at 10:20
  • @hakre, Added the source. Assumed that this content was available on the earlier linked manual of `password_hash()`. – Shankar Narayana Damodaran Mar 03 '14 at 10:25
1

It's fast. An attacker could break a hashed password in just a few hours (maybe minutes) if they managed to get a copy of your database - the faster an algorithm, the more attempts per second = more insecure.

SHA-256/SHA-512 are better choices as they take longer to process, therefore they could add years to the time it could take to break a hash. Not sure about the hackers out there, but I don't have the time or patience to try that.

jhmckimm
  • 870
  • 6
  • 15