View comments | RSS feed

Hash

Description

Converts a variable-length string to a 32-byte, hexadecimal string, using the MD5 algorithm. (It is not possible to convert the hash result back to the source string.)

Return value

32-byte, hexadecimal string

Category

Conversion functions, Other functions, String functions

Syntax

Hash(string)

Parameters

Parameter Description
string
A string or a variable that contains one.

Usage

The result is useful for comparison and validation. For example, a developer can store the hash of a password in a database without exposing the password. The developer can check the validity of the password with the following code:

<cfif hash(form.password) is not myQuery.passwordHash>
  <cflocation url = "unauthenticated.cfm">
</cfif>

Example

<!--- How to use Hash for password validation. This assumes that UserID 
value is passed to this page with a URL parameter. --->
<h3>Hash Example</h3>

<cfquery name = "CheckPerson" datasource = "UserData">
  SELECT PasswordHash
  FROM SecureData
  WHERE UserID = <cfqueryparam value = "#UserID#"
    cfsqltype = "CF_SQL_CHARVAR"> 
</cfquery>

<cfif Hash(form.password) is not checkperson.passwordHash>
  <cflocation url = "unauthenticated.cfm">
<cfelse>
  ...
</cfif>

ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6

Comments are no longer accepted for ColdFusion MX. ColdFusion 8 is the current version.

Comments


grizzlychicken said on Nov 12, 2003 at 2:49 PM :
So how would you give the password back to your user if they ever forgot it if it is hashed?
Zuchachass said on Nov 20, 2003 at 9:12 AM :
You can't. One thing you could do is provide your users a way of adding a 'password hint' to their accounts so they can retreive it and determine their password that way.
ThisIsMe said on Feb 20, 2004 at 1:47 PM :
Right, most sites offer a password generator for password recovery. when they can't recover a password. Better that way anyway... if someone gets the hint or has access to email and they hit forgot password they could know the person's password to not only the service in question but anywhere else the person might use the password.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6/CFML_Reference/functions-pt1113.htm