-
-
Save mjclemente/cd847450a880dcb63e0ca02b72233ba4 to your computer and use it in GitHub Desktop.
Hashify (UDF)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
/* | |
Hashify | |
http://brianflove.com/2015/02/24/hash-any-coldfusion-type/ | |
*/ | |
private string function hashify(required any value) { | |
//return an empty string for null | |
if (IsNull(arguments.value)) { | |
return ""; | |
} | |
//return a simple value | |
if (IsSimpleValue(arguments.value)) { | |
return Hash(arguments.value, "MD5"); | |
} | |
//return binary value in Base64 | |
if (IsBinary(arguments.value)) { | |
return hashify(value=ToBase64(arguments.value)); | |
} | |
//serialize ColdFusion objects | |
if (IsObject(arguments.value)) { | |
return hashify(value=ObjectSave(arguments.value)); | |
} | |
//struct | |
if (IsStruct(arguments.value)) { | |
var values = ""; | |
for (var key in arguments.value) { | |
values &= hashify(value=key) & hashify(value=arguments.value[key]); | |
} | |
return hashify(value=values); | |
} | |
//array | |
if (IsArray(arguments.value)) { | |
var values = ""; | |
for(var i=ArrayLen(arguments.value); i > 0; i--){ | |
values &= hashify(value=i) & hashify(value=arguments.value[i]); | |
} | |
return hashify(value=values); | |
} | |
//query | |
if (IsQuery(arguments.value)) { | |
return hashify(value=ObjectSave(arguments.value)); | |
} | |
} | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment