Skip to content

Instantly share code, notes, and snippets.

@homestar9
Created March 27, 2019 00:28
Show Gist options
  • Save homestar9/4d6929f09a2c2757a6604d546ebeadaa to your computer and use it in GitHub Desktop.
Save homestar9/4d6929f09a2c2757a6604d546ebeadaa to your computer and use it in GitHub Desktop.
Hashify (UDF)
<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