Learn how to Make Money Online doing freelancing, Affiliate Marketing, Blogging and many more ...
Go4Expert
Go4Expert RSS Feed

Go Back   Programming and SEO Forum >  Go4Expert > Articles / Source Code > Engineering concepts

Discuss / Comment  Copy HTML to Clipboard  Copy BBCode to Clipboard  | More
 
Bookmarks Article Tools Search this Article Display Modes

MD5 Tutorial


On 24th May, 2005
Lightbulb MD5 Tutorial

Show Printable Version Email this Page Subscription Add to Favorites Copy MD5 Tutorial link

Author

pradeep ( Team Leader )

Yet to provide details about himself


All articles By pradeep

Recent Articles

Similar Articles

What is MD5 or MD5sum?



Its a formula - a way to take a message of an arbitrary length, and create a 128-bit "fingerprint" or "message digest" of the message. MD5 is a way to verify data integrity. On these forums, it comes up fairly often in discussions about storing user passwords and other sensitive data.

Is MD5 encryption?



No. It is simply a one-way fingerprint of the message. It doesn't include the original message, and you can't (generally) use the fingerprint (the md5sum) to 'figure out' the original message.

Okay, so you take a message - like a password - and generate an MD5sum from it.. Can't you brute-force that?

Like any password system, you could attempt to brute force the answer. However, MD5sum's are in a 128-bit space, meaning that to brute force it would take 2^128 attempts - thats over 3 with 38 zeroes after it.

Neat! Thats a lot. Are there any flaws in the algorithm that could speed it up?

A birthday attack is based on the theory that there *might* be *one* md5sum that matches multiple inputs. In theory, it is possible that a "birthday" attack could be possible - two md5sum hashes could be the same. But even then, the total number of brute forces is at 2^64 attempts - still a heck of a lot.

Okay. But couldn't (insert super-sneaky government agency here) build an md5 dictionary, and know what the password was with the md5?

Yes. Its entirely possible. However - it would take some work to do so. For example, just for a dictionary consisting of Alphabet letters (upper and lower), and numbers, there would be 46,656,000,000 entries - all at 32 characters each. Thats over 1 terabyte of data to store and search! It could be done - absolutely. But is it likely?

So its hard to brute force, what about dictionary attacks?

Dictionary attacks are a way of attacking poor passwords - most people use words in their passwords. If you can guess the word - for example, "love", then you can cut down the number of tries it would take. Of course if you guess right, then your # of attacks = 1. However, in general, using common computers as of the writing of this (2005), you can generally get roughly 5 million attacks per second, or fast enough to guess all 8-character Alphanumericals within 497 days.

Thats pretty strong - but is there anything stronger?



A similar method is SHA1 - a more secure 160-bit hashing algorithm. That makes it *much* more secure against brute-force, birthday attacks, and other forms of assault. There are yet more hashing algorithms that are even stronger - but MD5 and SHA1 are both natively supported in the latest PHP, and should be sufficient for most projects.

Allright - I'm sold. Tell me how to use it to store passwords and check them

There are three things we are protecting against - the stored passwords, the transmission of the passwords, and the replay of the password. Each is very different. Lets start with the stored password. We need to take a password, and store it in a variable. Then we need to check that variable against what the user entered:
PHP Code:
$secret_password md5("password");
  
 if (
md5($_POST['password']) == $secret_password)
 {
     echo 
"Correct password";
  
 } else {
  
     echo 
"Incorrect password";
 } 
Simple enough. However, the password is being sent cleartext in $_POST['password']. Which brings us to another thing to protect against - the cleartext transmission. Thankfully, there is an opensource (GPL'd) javascript MD5 implementation available online which can be found here. If you use that javascript library to md5 the password before sending it, the server code would look like this instead:
PHP Code:
$secret_password md5("password");
  
 if (
$_POST['password'] == $secret_password)
 {
     echo 
"Correct password";
  
 } else {
  
     echo 
"Incorrect password";
 } 
Again, fairly simple. However, I mentioned the other problem - replay attacks. If someone could manage to 'sniff' the connection, and capture the md5sum, they could simply use that to login!

The solution to that can be very complex and involved - the same site for the javascript md5 function goes into great detail discussing how to implement a truly secure solution. It's called a "CHAP" login system, and here is a link to his page on it - including complete working PHP and javascript code to implement it.

MD5 is a very useful means to protect user's passwords online - if used correctly. Its not encryption, but it does help prevent whole databases of passwords being compromised.
Old 10-28-2005, 04:52 PM   #2
Go4Expert Member
 
AhmedHan's Avatar
 
Join Date: Oct 2005
Location: Ankara/Turkey
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
AhmedHan is on a distinguished road

Re: MD5 Tutorial


Thanks for the splendid info.

Do you know if there is any Win32 API or some stuff like that that generates MD5 code. I mean, I am looking for a function which is corresponding to the MD5() function of PHP, for using in C++. A DLL would be nice.
AhmedHan is offline   Reply With Quote
Old 10-29-2005, 04:04 AM   #3
Go4Expert Founder
 
shabbir's Avatar
 
Join Date: Jul 2004
Location: On Earth
Posts: 12,516
Thanks: 53
Thanked 276 Times in 215 Posts
Rep Power: 10
shabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud of
Send a message via Yahoo to shabbir

Re: MD5 Tutorial


Quote:
Originally Posted by AhmedHan
Thanks for the splendid info.

Do you know if there is any Win32 API or some stuff like that that generates MD5 code. I mean, I am looking for a function which is corresponding to the MD5() function of PHP, for using in C++. A DLL would be nice.
In dot net you can use the Cryptography interface to do it for you but in Win32 if you use the dotnet compiler the SDK can help you out but probably need the 3rd party DLL or Some SDK

Here is the MSDN link for the same MD5
shabbir is offline   Reply With Quote
Old 12-12-2006, 04:11 AM   #4
Newbie Member
 
Join Date: Dec 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
Becksbox is on a distinguished road

Re: MD5 Tutorial


Hi

Is it somehow possible to reverse engineer md5 hashes ?
I mean, i just found http://md5.rednoize.com and i wondered how this site works.
Becksbox is offline   Reply With Quote
Old 12-12-2006, 09:58 AM   #5
Go4Expert Member
 
AhmedHan's Avatar
 
Join Date: Oct 2005
Location: Ankara/Turkey
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
AhmedHan is on a distinguished road

Re: MD5 Tutorial


Here MD5 algorithm is explained :
http://en.wikipedia.org/wiki/Md5#Algorithm
AhmedHan is offline   Reply With Quote
Old 12-12-2006, 11:58 AM   #6
Team Leader
 
pradeep's Avatar
 
Join Date: Apr 2005
Location: Kolkata, India
Posts: 1,470
Thanks: 0
Thanked 35 Times in 30 Posts
Rep Power: 7
pradeep will become famous soon enough
Send a message via Yahoo to pradeep

Re: MD5 Tutorial


Its not possible to reverse engineer MD5 hashes, but what you can do is, make a database of of MD5 hashes and their corresponding words,and when you want to lookup what the hash orginally was generated from, just lookup the hash with the database to get the corresponding word.
But its not feasible to create a database of all possible strings.
__________________
Vote for the Most Entertaining Member of 2008

To err is human,to detect is divine!
pradeep is offline   Reply With Quote
Old 01-25-2007, 02:38 AM   #7
Go4Expert Member
 
ReekenX's Avatar
 
Join Date: Jan 2007
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
ReekenX is on a distinguished road

Re: MD5 Tutorial


Thanks. But I md5 is not safe in my opinion. It is possible that two or more words hashed will have the same value of md5?
__________________
http://www.webcore.lt - my personal web site, if you interested in web developing, please visit

Last edited by ReekenX; 01-21-2008 at 05:06 PM.
ReekenX is offline   Reply With Quote
Old 01-25-2007, 11:33 AM   #8
Team Leader
 
pradeep's Avatar
 
Join Date: Apr 2005
Location: Kolkata, India
Posts: 1,470
Thanks: 0
Thanked 35 Times in 30 Posts
Rep Power: 7
pradeep will become famous soon enough
Send a message via Yahoo to pradeep

Re: MD5 Tutorial


The probability of a collision is negligible.
__________________
Vote for the Most Entertaining Member of 2008

To err is human,to detect is divine!
pradeep is offline   Reply With Quote
Old 06-27-2007, 08:33 PM   #9
Go4Expert Member
 
Join Date: Jun 2007
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
kush_2207 is on a distinguished road

Re: MD5 Tutorial


Rainbow attacks have become the major threat for md5 and is put to use to crack md5 hashes....md5 would be gone in few years...SHA-1 and SHA-256 (its successor) would be put into practice more often....
kush_2207 is offline   Reply With Quote
Old 06-27-2007, 10:04 PM   #10
Go4Expert Member
 
AhmedHan's Avatar
 
Join Date: Oct 2005
Location: Ankara/Turkey
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
AhmedHan is on a distinguished road

Re: MD5 Tutorial


Quote:
Originally Posted by kush_2207
Rainbow attacks have become the major threat for md5 and is put to use to crack md5 hashes....
What is a rainbow attack?
AhmedHan is offline   Reply With Quote
Discuss / Comment  Copy HTML to Clipboard  Copy BBCode to Clipboard  | More


Currently Active Users Reading This Article: 1 (0 members and 1 guests)
 
Article Tools Search this Article
Search this Article:

Advanced Search
Display Modes
Bookmarks

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads / Articles
Thread Thread Starter Forum Replies Last Post
C-C++ books and tutorial shabbir C-C++ 4 07-25-2006 02:31 PM

 

All times are GMT +5.5. The time now is 05:37 AM.