Skip to content

Instantly share code, notes, and snippets.

@JamoCA
Last active October 18, 2023 18:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamoCA/b02a8e86f8f082b28ecb494d910e092d to your computer and use it in GitHub Desktop.
Save JamoCA/b02a8e86f8f082b28ecb494d910e092d to your computer and use it in GitHub Desktop.
Sanitize email and generate a unique integer hash using java hashCode & ColdFusion/CFML.
<cfscript>
/* 2023-03-21 by James Moberg (SunStar Media)
Sanitize email and generate a unique integer hash using java hashCode & ColdFusion/CFML.
GIST: https://gist.github.com/JamoCA/b02a8e86f8f082b28ecb494d910e092d
BLOG: https://dev.to/gamesover/generate-sanitized-email-hash-as-integer-4n3e
TWEET: https://twitter.com/gamesover/status/1638213875853307904
*/
public numeric function generateEmailHashCode(required string email) hint="I sanitize email and generate a unique integer hash using java hashCode" {
local.d = javacast("string", listlast(trim(arguments.email), "@"));
local.u = javacast("string", trim(listfirst(trim(arguments.email), "@")));
local.u = listfirst(local.u, "+").replaceAll("\.", "");
local.e = lcase(trim(local.u)) & "@" & lcase(trim(local.d));
return javacast("int", local.e.hashCode());
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment