Description

Provides a random token and stores it in the session. You can also provide a specific key to store in the session.

Returns

Token

Category

Display and formatting functions

Syntax

CSRFGenerateToken([key] [,forceNew])

See also

CSRFVerifyToken

History

ColdFusion 10: Added this function.

Parameters

Parameter

Required\Optional

Description

key

optional

A random token is generated based on the key provided. This key is stored in the session.

forceNew

optional

If set to true, a new token is generated every time the method is called. If false, in case a token exists for the key, the same key is returned.

Usage

Use this function to create a random token and store it in the session.

Example

<cfset csrfToken=CSRFGenerateToken() /> 
<cfform method="post" action="sayHello.cfm"> 
<cfinput name="userName" type="text" > 
<cfinput name="token" value="#csrfToken#" type="hidden" > 
<cfinput name="submit" value="Say Hello!!" type="submit" > 
</cfform>

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy