Last active
October 18, 2023 18:16
-
-
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.
This file contains 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> | |
/* 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