Password Security with Hashing Functions - Security Series #4.2
What is hashing?
From Wikipedia: "... a Cryptographic Hash Function is a transformation that takes an input and returns a fixed-size string, which is called the hash value.
To avoid confusion, and at the risk of being corrected by a smarty-pant, I will simplify and say that a hash function takes an input string, scrambles it up in a predictable manner and returns another string that cannot be reversed.
Let's look at some code.
If I take the following three values:
<cfset val1 = "Jason" />
<cfset val2 = "Model-Glue" />
<cfset val3 = "SR-71 Blackbird" />
and hash them using the popular MD5 hash function
<cfset hash1 = Hash(val1,"MD5") />
<cfset hash2 = Hash(val2,"MD5") />
<cfset hash3 = Hash(val3,"MD5") />
And output them to the screen
<cfoutput>
#hash1#<br />
#hash2#<br />
#hash3#<br />
</cfoutput>
I would get these values:
472D46CB829018F9DBD65FB8479A49BB
2429B9A443D9C21B0698ADBE2F6E01C0
10F1C46CAF873486E530570E7A298BBB
So regardless of the length of the input string, the results are all the same length, but with unique values.
Now, let's do that same hash again:
472D46CB829018F9DBD65FB8479A49BB
2429B9A443D9C21B0698ADBE2F6E01C0
10F1C46CAF873486E530570E7A298BBB
Oh, look at that, the exact same values. This is what I meant by "predictable" results. If you hash a string of text with the same hash function over and over again, you will always get the same result. That presents an issue that we will talk about when we discuss salting.
That's a very good question, and the answer is, you don't. What you do instead, is generate a random password (7 or 8 characters ought to do) and you Hash that and then send the new unhashed password to your user. The new password you send should be for one-time use only and should expire after a short time. Another option that many employ is to send the user a one-time unique, time-sensitive URL that they can click on and then reset the password themselves. Either method, I think, is acceptable.
If you asked that question, then Kudos! Bravo Zulu, to you. That is the exact right question ask. You should become a security professional. What you are describing there, in essence, is a rainbow table. A rainbow table is a look up table of possible hash values for common passwords, credit card numbers, or any other data that could be obfuscated through hashing. The existence of rainbow tables adds another step to our password security. Fortunately, it is an easy step. It is called "salting".



Just so I am clear on Hashing, it is possible for two strings to result in the same hash value, right?
Also, if a hash value is 32 characters long, and the value you are hashing is greater than 32 characters long, does that make it any harder to "crack"?
Looking forward to next part.
@Ben
The answer to the first part was getting too long, soI made a new entry for it. You can find it here, http://www.12robots.com/index.cfm?event=showEntry&...
Or if that link doesn;t work, then it is entry 4.2.1 of the security series.
I am hoping the post also answers your second question, since in most cases we will not be using the 32 character MD5 hash.