Created
November 29, 2021 13:28
-
-
Save trycf/75b3994be85aa042127e946905e29518 to your computer and use it in GitHub Desktop.
TryCF Gist
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> | |
writeOutput( generateTokenValue( 20 ) ); | |
// ------------------------------------------------------------------------------- // | |
// ------------------------------------------------------------------------------- // | |
/** | |
* I generate a cryptographically secure random token with the given length. | |
*/ | |
public string function generateTokenValue( numeric tokenLength = 200 ) { | |
var letters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
var letterCount = letters.len(); | |
var parts = []; | |
for ( var i = 1 ; i <= tokenLength ; i++ ) { | |
parts.append( letters[ randRange( 1, letterCount, "SHA1PRNG" ) ] ); | |
} | |
return( parts.toList( "" ) ); | |
} | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment