Function Forum: Hash()

 
Dec 27, 1999
by Michael Dinowitz

Password encryption is a key to many sites, from intranets to E-Commerce. ColdFusion has a few functions that do encryption in one form or another, but they all have a single flaw. If someone has hacked into your site and obtained the encrypted value, as well as the encryption key, they can reverse the process and find out a user's password. This is rather important, because most people keep using the same password from site to site. If you know their password on one site, you probably know it on a host of others.

A perfect solution to this would be to have the encrypted value of their password be a one-way encryption. In the past, this was done using a ColdFusion extension called CFX_Hash. This extension has proven to be rather useful for security. It must have gotten some supporters inside Allaire, as they've decided to incorporate the functionality of this extension into the core of ColdFusion.

The Hash() function will take any string value and turn it into a 32-bit encrypted string. This is a one-way encryption that will always return the same-sized results. The only problem with this function is that it is not documented in the ColdFusion 4.5 documentation.

Using some experimentation, I've compiled the following profile for the function. I'm not sure exactly how the encrypted value is generated, but I'm sure someone will tell me once they read this article.


Hash

(string)

string

(Required; accepts: String) String to be encrypted.

This function will take a string and do a one-way encryption of it. The result will be a 32-bit hexadecimal value. The encrypted value is a one-way hash that can not be reversed.
<CFSET Test1=Hash(1)>
<CFSET Test2=Hash(2)>
<CFSET Test3=Hash(3)>
<CFSET Test4=Hash('a')>
<CFSET Test5=Hash('b')>
<CFSET Test6=Hash('Michael')>

<CFOUTPUT>
#Test1#<BR>
#Test2#<BR>
#Test3#<BR>
#Test4#<BR>
#Test5#<BR>
#Test6#<BR>
</CFOUTPUT>
		
Results:
C4CA4238A0B923820DCC509A6F75849B
C81E728D9D4C2F636F067F89CC14862C
ECCBC87E4B5CE2FE28308FD9F2A7BAF3
0CC175B9C0F1B6A831C399E269772661
92EB5FFEE6AE2FEC3AD71C777531578F
3E06FA3927CBDF4E9D93BA4541ACCE86
Data Type:
Category:
Version:
Related Functions:

String
Crypto
4.5
CFusion_Encrypt, Encrypt

Privacy | FAQ | Site Map | About | Guidelines | Contact | Advertising | What is ColdFusion?
House of Fusion | ColdFusion Jobs | Blog of Fusion | AHP Hosting